spring-注解实现入门
2014-09-29 17:38
260 查看
一.创建项目
项目名称:spring092902
二.添加jar包
1.在项目中创建lib目录
/lib
2.在lib目录下添加jar包
commons-logging.jar
junit-4.4.jar
log4j.jar
spring-beans-3.2.0.RELEASE.jar
spring-context-3.2.0.RELEASE.jar
spring-core-3.2.0.RELEASE.jar
spring-expression-3.2.0.RELEASE.jar
三.添加配置文件
1.在项目中创建conf目录
/conf
2.在conf目录下添加配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 解析注解 -->
<context:annotation-config />
<!-- 扫描注解 -->
<context:component-scan base-package="cn.jbit.spring092902.service"></context:component-scan>
</beans>
四.创建bean
1.在src目录下创建包
cn.jbit.spring092902.service
2.在包下创建bean
bean名称:HelloService.java
bean内容:
@Component("helloService")
public class HelloService {
public void sayHello(){
System.out.println("hello");
}
}
五.测试
1.在项目中创建test目录
/test
2.在test目录下创建包
cn.jbit.spring092902.service
3.在包下创建测试类
测试类名:HellpServiceTest.java
测试类内容:
public class HellpServiceTest {
@Test
public void testSayHello(){
ApplicationContext con = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
HelloService helloService = (HelloService) con.getBean("helloService");
helloService.sayHello();
}
}
本文出自 “素颜” 博客,请务必保留此出处http://suyanzhu.blog.51cto.com/8050189/1559504
项目名称:spring092902
二.添加jar包
1.在项目中创建lib目录
/lib
2.在lib目录下添加jar包
commons-logging.jar
junit-4.4.jar
log4j.jar
spring-beans-3.2.0.RELEASE.jar
spring-context-3.2.0.RELEASE.jar
spring-core-3.2.0.RELEASE.jar
spring-expression-3.2.0.RELEASE.jar
三.添加配置文件
1.在项目中创建conf目录
/conf
2.在conf目录下添加配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 解析注解 -->
<context:annotation-config />
<!-- 扫描注解 -->
<context:component-scan base-package="cn.jbit.spring092902.service"></context:component-scan>
</beans>
四.创建bean
1.在src目录下创建包
cn.jbit.spring092902.service
2.在包下创建bean
bean名称:HelloService.java
bean内容:
@Component("helloService")
public class HelloService {
public void sayHello(){
System.out.println("hello");
}
}
五.测试
1.在项目中创建test目录
/test
2.在test目录下创建包
cn.jbit.spring092902.service
3.在包下创建测试类
测试类名:HellpServiceTest.java
测试类内容:
public class HellpServiceTest {
@Test
public void testSayHello(){
ApplicationContext con = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
HelloService helloService = (HelloService) con.getBean("helloService");
helloService.sayHello();
}
}
本文出自 “素颜” 博客,请务必保留此出处http://suyanzhu.blog.51cto.com/8050189/1559504
相关文章推荐
- Spring入门Blog[五、Spring@Component和Resouces实现注解配置]
- AOP之Spring使用注解方式实现AOP(入门)
- Spring入门_bean配置与注解实现
- Spring入门——Bean管理的注解实现及例子
- SpringBoot入门-20(springboot集成mybatis注解形式properties配置,利用@Provider实现动态SQL)
- RabbitMQ入门-10-3(整合spring-发送异步消息注解实现)
- Spring入门Blog[五、Spring容器组建注解@Component和Resouces实现完全注解配置]
- ITCAST视频-Spring学习笔记(使用Spring的注解方式实现AOP入门)
- SpringBoot入门-17(springboot集成mybatis注解形式实现ID自动增长)
- SpringBoot入门-19(springboot集成mybatis注解形式增删查改properties配置,利用《script》实现动态SQL)
- SpringBoot入门-12-1(springboot配置servlet,利用注解实现)
- RabbitMQ入门-10-2(整合spring-发送同步消息注解实现)
- 使用Spring的注解方式实现AOP入门
- Spring自动注入,利用注解实现spring基本配置详解,Spring注解快速入门
- (9) 使用Spring的注解方式实现AOP入门 以及 细节
- SpringBoot入门-21(springboot集成mybatis注解形式增删查改properties配置,利用@Provider实现动态SQL)
- spring hibernate注解实现泛型dao
- 使用Spring的注解方式实现AOP入门
- 第五章 Spring进阶-注解方式实现AOP(3)-全文完
- Spring注解入门