spring HelloWorld!
来源:互联网 发布:传奇npc算法 编辑:程序博客网 时间:2024/06/05 23:58
spring会自动帮你管理你的类的生命周期
创建第一个spring例子
导入相关的jar包(spring.jar commons-logging.jar)(http://pan.baidu.com/s/1pKQYwqv)
HelloWorld.java
public class HelloWorld {public void hello(){System.out.println("hello world");}}
在src目录下创建一个spring的配置文件
applicationContext.xml
<?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-2.5.xsd"><!-- 将一个类放进spring容器中 id值得唯一的--><bean id="helloWorld" class="com.mo.entity.HelloWorld"> </bean> </beans>
测试
public class HelloWorldTest {@Testpublic void testHello(){//加载配置文件,启动spring容器ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");//调用getbean方法,spring自动帮你创建一个对象返回HelloWorld helloWorld = (HelloWorld)context.getBean("helloWorld");helloWorld.hello();}}
打印输出
hello world
0 0
- Spring helloworld
- spring helloworld
- spring helloworld
- Spring -- HelloWorld
- spring helloworld
- Spring HelloWorld
- Spring--HelloWorld
- spring HelloWorld!
- spring-HelloWorld
- spring helloworld
- Spring-HelloWorld
- spring HelloWorld
- spring-1:Spring helloWorld
- Spring 之spring helloworld
- 从HelloWorld到Spring
- Spring-HelloWorld搭建
- spring mvc helloworld
- Spring Security helloworld
- A 房间安排
- Springboot 跑单元测试
- Flex布局
- 支持向量机--SVM入门
- webstrom less 配置
- spring HelloWorld!
- 关于使用hadoop出各种错的一些积累
- python,apt-get安装包位置
- com.caucho.jsp.JspParseException Resin can't load com.sun.tools.javac.Main
- Ubuntu14.04源码编译安装CPU版本的tensorflow
- iOS开发微信、QQ应用名称修改
- Linux网络编程中EAGAIN错误和EINTR错误
- JRebel 7.0激活Idea测试
- 通过进程名获取窗口句柄