bean装配--注解
1,Dao层
package com.songyan.zhujie;
public interface UserDao {
public void say();
}
package com.songyan.zhujie;
import org.springframework.stereotype.Repository;
@Repository("userDao")
public class UserDaoImpl implements UserDao {
public void say() {
System.out.println("dao say ");
}
}
2,Service层
package com.songyan.zhujie;
public interface UserService {
public void say();
}
package com.songyan.zhujie;
import org.springframework.stereotype.Repository;
@Repository("userDao")
public class UserDaoImpl implements UserDao {
public void say() {
System.out.println("dao say ");
}
}
3,Controller层
package com.songyan.zhujie;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
@Controller("contraller")
public class UserController {
@Resource(name="userService")
private UserService userService;
public void say(){
userService.say();
System.out.println("controller say");
}
}
4,配置
<?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-4.3.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<context:component-scan base-package="com.songyan.zhujie" />
</beans>
5,测试
package com.songyan.zhujie; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class TestZhujie {
public static void main(String[] args) {
ApplicationContext applicationContext=new ClassPathXmlApplicationContext("com/songyan/zhujie/beans6.xml");
UserController userController=(UserController)applicationContext.getBean("contraller");
userController.say(); } }
6,结果

bean装配--注解的更多相关文章
- IOC装配Bean(注解方式)
Spring的注解装配Bean Spring2.5 引入使用注解去定义Bean @Component 描述Spring框架中Bean Spring的框架中提供了与@Component注解等效的三个注解 ...
- Spring Bean装配(下)——注解
@Repository,@Service,@Controller这三个注解是基于component定义的注解 component-scan:组件扫描 base-package:扫描这个下的所有类 &l ...
- 002-Spring4 快速入门-项目搭建、基于注解的开发bean,Bean创建和装配、基于注解的开发bean,Bean初始化销毁、Bean装配,注解、Bean依赖注入
一.项目搭建 1.项目创建 eclipse→project explorer→new→Project→Maven Project 默认配置即可创建项目 2.spring配置 <dependenc ...
- Spring学习(七)bean装配详解之 【通过注解装配 Bean】【自动装配的歧义解决】
自动装配 1.歧义性 我们知道用@Autowired可以对bean进行注入(按照type注入),但如果有两个相同类型的bean在IOC容器中注册了,要怎么去区分对哪一个Bean进行注入呢? 如下情况, ...
- Spring学习(六)bean装配详解之 【通过注解装配 Bean】【基础配置方式】
通过注解装配 Bean 1.前言 优势 1.可以减少 XML 的配置,当配置项多的时候,XML配置过多会导致项目臃肿难以维护 2.功能更加强大,既能实现 XML 的功能,也提供了自动装配的功能,采用了 ...
- 【Spring】Spring的bean装配
前言 bean是Spring最基础最核心的部分,Spring简化代码主要是依赖于bean,下面学习Spring中如何装配bean. 装配bean Spring在装配bean时非常灵活,其提供了三种方式 ...
- Spring框架系列(二)之Bean的注解管理
微信公众号:compassblog 欢迎关注.转发,互相学习,共同进步! 有任何问题,请后台留言联系! 1.Spring中的两种容器 在系列(一)中我们已经知道,Spring 是管理对象的容器,其中有 ...
- Spring系列(三) Bean装配的高级技术
profile 不同于maven的profile, spring的profile不需要重新打包, 同一个版本的包文件可以部署在不同环境的服务器上, 只需要激活对应的profile就可以切换到对应的环境 ...
- Spring使用笔记(二)Bean装配
Bean装配 Spring提供了3种装配机制: 1)隐式的Bean发现机制和自动装配 2)在Java中进行显示装配 3)在XML中进行显示装配 一)自动化装配 1.指定某类为组件类: @Compone ...
随机推荐
- python3.x 安装命令
在root下执行下面的命令即可: sudo apt-get install python3-dev build-essential libssl-dev libffi-dev libxml2 libx ...
- JNDI和JDBC的区别和联系及其使用方法
一.JNDI 和JDBC的区别和联系 两者都是API,是连接数据库的标准.并不是什么产品或方法. 二.JDBC 全称:Java Database Connectivity 以一种统一的方式来对各种各样 ...
- HDU 4681 String 胡搞
设串C的第一个字母在串A中出现的位置是stA, 串C的最后一个字母在串A中出现的位置是edA. 设串C的第一个字母在串B中出现的位置是stB, 串C的最后一个字母在串B中出现的位置是edB. 求出每一 ...
- 【bzoj3866】The Romantic Hero dp
题目描述 给你n个数,从中选出两个不相交非空集合S和T,使得S中的每一个元素都在T集合的前面,并且S集合中的所有数的亦或等于T集合中的所有数的与,求方案数 mod 10^9+7. 输入 The fir ...
- 分享下自己一直用的.NET SQLSERVER 封装类下自己写的DataHelper 操作类
一,概述: 这个DataHelper 类是基于我上个博客里发的SQLDataAccess 这个类做的一个简单的封装,为了结合自己的实体类和数据操作而产生的. 这里面用了 属性类,反射.还有 数据类型 ...
- 51Nod 1317 相似字符串对
题目链接 分析: 考虑两个串的关系:$A+C=C+B$,我们观察可以发现,$A$和$B$是循环同构的,如果$A=G+H$,那么$B=H+G$,证明略长懒得写了... 我们知道$A$串有$K^N$种,所 ...
- quartz 调度
1.POI文件中导入包 <dependency> <groupId>org.quartz-scheduler</groupId> <artifact ...
- USACO silver P1
原题概述题意: 共有N个数,每个数的个数为ai,ai的总和为M,将每2个数进行配对,要求使配对之后2数的和的最大值最小,并输出最小值. 这不就是裸的贪心么..实在是水题啊, 不过如果假如有一个人要一个 ...
- sqlmap注入一般步骤
1. 找到注入点url2. sqlmap -u url -v 1--dbs 列出数据库或者 sqlmap -u url -v 1 --current-db 显示当前数据库3. sqlmap -u ur ...
- POCO C++ SOCKET
// client program #include "Poco/Net/DatagramSocket.h" #include "Poco/Net/SocketAddre ...