工具和环境:
-----------------------------------------------------------------------------
Eclipse版本:eclipse-jee-luna-R-win32
JDK版本:jdk1.7.0_21
Spring版本:spring-framework-4.0.0.RELEASE-dist
步骤:
-----------------------------------------------------------------------------
1. 新建Java工程
2. 把以下 jar 包加入到工程的 classpath 下:
2.1 spring包:
spring-framework-4.0.0.RELEASE-dist:
spring-beans-4.0.0.RELEASE.jar
spring-context-4.0.0.RELEASE.jar
spring-core-4.0.0.RELEASE.jar
spring-expression-4.0.0.RELEASE.jar
2.2 commons包:
commons-logging-1.1.1.jar
3. 添加类Helloworld
package xyz.huning.spring4.helloworld; public class Helloworld { private String username; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public void say() { System.out.println("hello: " + this.username); } }
4. 添加Spring 的配置文件(一个典型的 Spring 项目需要创建一个或多个 Bean 配置文件, 这些配置文件用于在 Spring IOC 容器里配置 Bean. Bean 的配置文件可以放在 classpath 下, 也可以放在其它目录下。)
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- 配置一个 bean --> <bean id="helloWorld" class="xyz.huning.spring4.helloworld.Helloworld"> <!-- 为属性赋值 --> <property name="username" value="Rabbit"></property> </bean> </beans>
5. 添加测试类Main
package xyz.huning.spring4.helloworld; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Main { public static void main(String[] args) { // 1. 创建Spring的IOC容器 // ApplicationContext代表IOC容器 // ClassPathXmlApplicationContext:从 类路径下加载配置文件 ApplicationContext context = new ClassPathXmlApplicationContext("helloworld.xml"); // 2. 从IOC容器中获取bean Helloworld helloworld = context.getBean("helloWorld", Helloworld.class); helloworld.say(); ((ClassPathXmlApplicationContext)context).close(); } }
6. 执行测试类的main方法
相关推荐
Spring4 HelloWorld初学Spring,java bean通过applicationContext.xml配置SpringIoC容器生成。
spring cloud 微服务helloworld项目,适合新手,项目基于spring cloud 微服务技术,使用了eureka注册公司,configserver配置中心,项目需要在本地新建配置中心配置文件
spring4-mvc-gradle-xml-hello-world, Gradle + spring 4 MVC Hello World 示例( XML ) Gradle --spring-4 MVC Hello Worldspring 4 MVC + JSP视图+ XML配置模板,使用Gradle构建工具。使用的###1. 技术Gradle 2.0...
第一次共享自己的代码,Spring Hello World。代码比较简单,适合初学者,入门使用。高手就不要下载。呵呵。
这是spring MVC的HelloWorld完整实例,包含jar包
spring笔记一helloworld,只是我学习spring框架,建立的第一个工程文件,导入的jar包,我的第一个spring- helloworld
博客示例代码,Spring boot 自学笔记(一) hello world 代码
spring和rabbitmq整合的helloworld
实现spring mvc 之helloworld
我自己写的Spring MVC的一个HelloWold,从建HelloWorld工程,搭建环境Install spring,配置web.xml,配置SpringMVC的配置文件springDispatcherServlet-servlet.xml,添加控制器类,建jsp页面,部署 Tomcat,最后运行...
根据学习笔记整理的HelloWorld,需要自行下载Spring3相关的包
spring-mvc-helloworld 可以通过jetty启动,访问 http://localhost:8010/spring-mvc-helloworld/hello/world
博文链接:https://hintcnuie.iteye.com/blog/198673
NULL 博文链接:https://jiaozhiguang-126-com.iteye.com/blog/1843178
Spring MVC3.05,helloworld实例。含完整jar包。
编译通过了,是在Eclipse平台开发Spring程序的小例子。入门可以看看~~
spring5.0的mvc项目实例,HelloWorld实例,基于eclipse oxygen jee 的maven project
Spring AMQP hello world
spring-mvc的一个helloworld的demo,需要的拿去用
采用spring3.0 mvc 注解的方式,在页面显示helloworld