spring 注解(spring所使用的所有jar)

来源:互联网 发布:httppost发送json 编辑:程序博客网 时间:2024/04/29 09:04
 

spring 注解(spring所使用的所有jar)

标签: springjarstringjavaclassbean
 13248人阅读 评论(0) 收藏 举报

需要四个东西

1 jar 2 默认构造方法 3bean.xml中添加相应语句 4@Resource

1 下面列出所用到的spring 的jar包


aspectjrt.jar   aspectweaver.jar cglib-nodep-2.1_3.jar

common-annotation.jar commons-logging.jar

spring.jar


如果使用到了jdbc

还要使用两个jar文件

commons-dbcp.jar

commons-pool.jar

mysql-connector-java-5.1.18-bin.jar

cn.dao

[java] view plaincopy
  1. <pre name="code" class="java">package cn.dao;  
  2.   
  3. public interface PersonDaoInterface {  
  4.   
  5.     public abstract void add();  
  6.   
  7. }  


cn.dao.imp

[java] view plaincopy
  1. package cn.dao.imp;  
  2.   
  3. import cn.dao.PersonDaoInterface;  
  4.   
  5. public class PersonDao implements PersonDaoInterface {  
  6.     public void add()  
  7.     {  
  8.         System.out.println("执行PersonDao.add()");  
  9.     }  
  10.   
  11. }  
cn.service

[java] view plaincopy
  1. package cn.service;  
  2.   
  3. public interface PersonService {  
  4.   
  5.     public abstract void save();  
  6.   
  7. }  
cn.service.imp

[java] view plain copy
  1. package cn.service.imp;  
  2.   
  3.   
  4.   
  5. import javax.annotation.Resource;  
  6.   
  7. import org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor;  
  8.   
  9. import cn.dao.imp.PersonDao;  
  10. import cn.service.PersonService;  
  11.   
  12. public class PersonServiceBean implements PersonService {  
  13.       
  14.     private String name;  
  15.     @Resource private PersonDao personDao;  
  16.       
  17.     public PersonServiceBean(){}  
  18.       
  19.     public PersonServiceBean(String name,PersonDao personDao) {  
  20.         this.name = name;  
  21.         this.personDao=personDao;  
  22.     }  
  23.   
  24.     public String getName() {  
  25.         return name;  
  26.     }  
  27.   
  28.     public void setName(String name) {  
  29.         this.name = name;  
  30.     }  
  31.   
  32.     public PersonDao getPersonDao() {  
  33.         return personDao;  
  34.     }  
  35.   
  36.     public void setPersonDao(PersonDao personDao) {  
  37.         this.personDao = personDao;  
  38.     }  
  39.   
  40.     public void save()  
  41.     {  
  42.         personDao.add();  
  43.         //System.out.println(name);  
  44.           
  45.     }  
  46. }  


juintest

[java] view plaincopy
  1. package junit.test;  
  2.   
  3. import org.junit.Test;  
  4. import org.springframework.context.ApplicationContext;  
  5. import org.springframework.context.support.AbstractApplicationContext;  
  6. import org.springframework.context.support.ClassPathXmlApplicationContext;  
  7.   
  8. import cn.service.imp.PersonServiceBean;  
  9.   
  10.   
  11. public class SpringTest   
  12. {  
  13.     @Test   
  14.     public void instanceSpring()  
  15.     {  
  16.         AbstractApplicationContext ctx=new ClassPathXmlApplicationContext(new String[]{"beans.xml"});  
  17.         PersonServiceBean personServiceBean=(PersonServiceBean) ctx.getBean("personService");  
  18.         personServiceBean.save();  
  19.         ctx.close();  
  20.     }  
  21. }  

bean.xml


[html] view plain copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.        xmlns:context="http://www.springframework.org/schema/context"  
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans  
  6.            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
  7.            http://www.springframework.org/schema/context  
  8.            http://www.springframework.org/schema/context/spring-context-2.5.xsd">  
  9.         <context:annotation-config></context:annotation-config>  
  10.         <bean id="personDao" class="cn.dao.imp.PersonDao"></bean>  
  11.         <bean id="personService" class="cn.service.imp.PersonServiceBean">  
  12.         </bean>  
  13.   
  14. </beans>