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 ...
随机推荐
- django-settings里redis连接与缓存配置
# Django-redis的缓存配置 CACHES = { "default": { "BACKEND": "django_redis.cache. ...
- OZ customize windows iamge
1.之前通过修改auto文件和windows.py文件可实现自动安装OS,但是disk bus只能以IDE模式启动,进入系统自动下载运行bat文件,安装cloudbase-init和qga,及清理日志 ...
- pytorch版本问题:AttributeError: 'module' object has no attribute '_rebuild_tensor_v2'
用pytorch加载训练好的模型的时候遇到了如下的问题: AttributeError: 'module' object has no attribute '_rebuild_tensor_v2' 到 ...
- shell之netstat命令
语 法:netstat [-acCeFghilMnNoprstuvVwx] [-A<网络类型>][--ip] 补充说明:利用netstat指令可让你得知整个Linux系统的网络情况. ...
- SVN基本介绍
SVN是一种项目合作开发的软件,参与项目的人员可以在不同的地方实现文件和目录的超时空共享. 两个重要的概念: 1.配置库(Repository) SVN的核心是配置库,储存所有的数据,配置库按照文件树 ...
- 网络namespace
sduo sysctl -w net.ipv4.conf.all.forwarding=1 sudo iptables -t nat -A POSTROUTING -s 172.18.0.0/24 ...
- [洛谷P1792][国家集训队]种树
题目大意:给出由$n$个数组成的环,取某个数就可以得到它的分数,相邻的两个数不能同时取.问取$m$个数可以得到的最大分数. 题解:建一个大根堆,贪心取,每个点记录前驱后继,取一个点就把前驱后继设成不能 ...
- POJ 3264 Balanced Lineup | st表
题意: 求区间max-min st表模板 #include<cstdio> #include<algorithm> #include<cstring> #inclu ...
- bzoj 3309 DZY Loves Math 莫比乌斯反演
DZY Loves Math Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 1303 Solved: 819[Submit][Status][Dis ...
- Restful 权限的思考
转自:https://cnodejs.org/topic/551802d3687c387d2f5b2906 基于RESTful API 怎么设计用户权限控制? 原文链接:简书 前言 有人说,每个人 ...