spring @Resource + @Component
来源:互联网 发布:百度云签到源码 编辑:程序博客网 时间:2024/06/16 13:02
beans.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" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"><context:annotation-config></context:annotation-config><context:component-scan base-package="com.bjsxt"/></beans>
UserDAOImpl
package com.bjsxt.dao.impl;import java.util.LinkedHashMap;import java.util.List;import java.util.Set;import org.springframework.stereotype.Component;import com.bjsxt.dao.UserDAO;import com.bjsxt.model.User;@Component("uu")public class UserDAOImpl implements UserDAO {private Set<String> sets;private List<String> lists;private LinkedHashMap<String, String> maps;private String daoId;public String getDaoId() {return daoId;}public void setDaoId(String daoId) {this.daoId = daoId;}public Set<String> getSets() {return sets;}public LinkedHashMap<String, String> getMaps() {return maps;}public void setMaps(LinkedHashMap<String, String> maps) {this.maps = maps;}public void setSets(Set<String> sets) {this.sets = sets;}public List<String> getLists() {return lists;}public void setLists(List<String> lists) {this.lists = lists;}@Overridepublic String toString() {// TODO Auto-generated method stub//return "sets size:" + sets.size() + "| lists size:" + lists.size() + "| maps size:" + maps.size();return daoId;}public void save(User user) {//Hibernate//JDBC//XML//NetWorkSystem.out.println("user saved!");}}
userservice
package com.bjsxt.service;import javax.annotation.Resource;import org.springframework.stereotype.Component;import com.bjsxt.dao.UserDAO;import com.bjsxt.model.User;@Component("uuuService")public class UserService {private UserDAO userDAO; public void add(User user) {userDAO.save(user);}public UserDAO getUserDAO() {return userDAO;}@Resource(name="uu")public void setUserDAO( UserDAO userDAO) {this.userDAO = userDAO;}}
test
package com.bjsxt.service;import org.junit.Test;import org.springframework.beans.factory.BeanFactory;import org.springframework.context.support.ClassPathXmlApplicationContext;import com.bjsxt.model.User;public class UserServiceTest {@Testpublic void testAdd() throws Exception {BeanFactory applicationContext = new ClassPathXmlApplicationContext("beans.xml");UserService service = (UserService)applicationContext.getBean("uuuService");service.add(new User());}}
- spring @Resource + @Component
- Spring @Autowired@Component@ Resource注解
- Spring注解@Component和@resource的使用
- spring中@Component @resource注解的说明
- Spring注解@Component和@resource的使用
- Spring注解@Component和@resource的使用
- Spring @Resource @Autowired @Component常用注解
- Spring中注解@Bean、@Resource、@Component、@SpringStudy
- spring mvc 注解基本配置(@resource,@autowired,@Component...)
- spring mvc 注解基本配置(@resource,@autowired,@Component...)
- Spring注解@Component、@Repository、@Service、@Controller @Resource、@Autowired、@Qualifier 解析
- Spring注解@Component、@Repository、@Service、@Controller @Resource、@Autowired、@Qualifier 解析
- Spring注解@Component、@Repository、@Service、@Controller @Resource、@Autowired、@Qualifier 解析
- Spring注解@Component、@Repository、@Service、@Controller @Resource、@Autowired、@Qualifier 解析
- Spring注解@Component、@Repository、@Service、@Controller @Resource、@Autowired、@Qualifier 解析
- Spring注解@Component、@Repository、@Service、@Controller @Resource、@Autowired、@Qualifier、@scope
- Spring注解@Component、@Repository、@Service、@Controller @Resource、@Autowired、@Qualifier 解析
- Spring中@Resource与@Autowired与@Component注解的总结
- QT5.0.2 安装+入门例子(windows下)
- openwrt中继设置方法
- T大佬玩跨界搭上女神 丁磊林志玲合唱《带我飞》
- Apache Maven 入门篇(下)
- SuperScan
- spring @Resource + @Component
- CGAffineTransform与CABasicAnimation
- html嵌入swf文件
- 行内元素与块级元素的区别
- openwrt挂载U盘
- js变量以及其作用域详解
- Ural 1028. Stars
- A. Winner
- 安装nagios-plugins-1.4.15的make的报错