1,Dao

  1. package com.songyan.autoZhuangpei;
  2.  
  3. public interface UserDao {
  4. public void say();
  5.  
  6. }
  1. package com.songyan.autoZhuangpei;
  2.  
  3. import org.springframework.stereotype.Repository;
  4.  
  5. public class UserDaoImpl implements UserDao {
  6.  
  7. public void say() {
  8. System.out.println("dao say ");
  9.  
  10. }
  11. }

2,Service

  1. package com.songyan.autoZhuangpei;
  2.  
  3. public interface UserService {
  4. public void say();
  5. }
  1. package com.songyan.autoZhuangpei;
  2.  
  3. import javax.annotation.Resource;
  4.  
  5. import org.springframework.stereotype.Service;
  6.  
  7. public class UserServiceImpl implements UserService {
  8.  
  9. private UserDao userDao;
  10.  
  11. public UserDao getUserDao() {
  12. return userDao;
  13. }
  14.  
  15. public void setUserDao(UserDao userDao) {
  16. this.userDao = userDao;
  17. }
  18.  
  19. public void say() {
  20. userDao.say();
  21. System.out.println("service say");
  22.  
  23. }
  24. }

3,Servlet

  1. package com.songyan.autoZhuangpei;
  2.  
  3. import javax.annotation.Resource;
  4.  
  5. import org.springframework.stereotype.Controller;
  6.  
  7. public class UserController {
  8.  
  9. private UserService userService;
  10. public UserService getUserService() {
  11. return userService;
  12. }
  13. public void setUserService(UserService userService) {
  14. this.userService = userService;
  15. }
  16. public void say(){
  17. userService.say();
  18. System.out.println("controller say");
  19. }
  20.  
  21. }

4,配置

  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" xmlns:context="http://www.springframework.org/schema/context"
  4. 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">
  5. <bean id="userDao" class="com.songyan.autoZhuangpei.UserDaoImpl" autowire="byName"/>
  6. <bean id="userService" class="com.songyan.autoZhuangpei.UserServiceImpl" autowire="byName"/>
  7. <bean id="userContraller" class="com.songyan.autoZhuangpei.UserController" autowire="byName"/>
  8.  
  9. </beans>

5,Test

  1. package com.songyan.autoZhuangpei;
  2.  
  3. import org.springframework.context.ApplicationContext;
  4. import org.springframework.context.support.ClassPathXmlApplicationContext;
  5.  
  6. public class TestZhujie {
  7. public static void main(String[] args) {
  8. ApplicationContext applicationContext=new ClassPathXmlApplicationContext("com/songyan/autoZhuangpei/beans6.xml");
  9. UserController userController=(UserController)applicationContext.getBean("userContraller");
  10. userController.say();
  11.  
  12. }
  13.  
  14. }

6,结果

bean装配--auto的更多相关文章

  1. Bean 装配,从 Spring 到 Spring Boot

    目录  从SSM的集成谈到Bean的装配  Bean的装配 由XML到Java Config 自动扫描 Bean的注入 SSM集成的Java版 Spring Boot Magic Auto Confi ...

  2. 【Spring】Spring的bean装配

    前言 bean是Spring最基础最核心的部分,Spring简化代码主要是依赖于bean,下面学习Spring中如何装配bean. 装配bean Spring在装配bean时非常灵活,其提供了三种方式 ...

  3. 使用spring框架,用xml方式进行bean装配出现“The fully qualified name of the bean's class, except if it serves...”

    使用spring框架,用xml方式进行bean装配出现“The fully qualified name of the bean's class, except if it serves...”. 原 ...

  4. Spring使用笔记(二)Bean装配

    Bean装配 Spring提供了3种装配机制: 1)隐式的Bean发现机制和自动装配 2)在Java中进行显示装配 3)在XML中进行显示装配 一)自动化装配 1.指定某类为组件类: @Compone ...

  5. Spring对Bean装配详解

    1.Spring提供了三种装配bean的方式: 2.自动装配bean: 3.通过Java代码装配bean 4.通过XML装配bean 前言:创建对象的协作关系称为装配,也就是DI(依赖注入)的本质.而 ...

  6. Spring Bean装配学习

    解释:所谓装配就是把一个类需要的组件给它设置进去,英文就是wire,wiring:注解Autowire也叫自动装配. 目前Spring提供了三种配置方案: 在XML中进行显式的配置 在Java中进行显 ...

  7. spring Bean装配的几种方式简单介绍

    Spring容器负责创建应用程序中的bean同时通过ID来协调这些对象之间的关系.作为开发人员,我们需要告诉Spring要创建哪些bean并且如何将其装配到一起. spring中bean装配有两种方式 ...

  8. Bean装配--xml

    1,bean package com.songyan.zhangpei; import java.util.ArrayList; import com.sun.xml.internal.bind.v2 ...

  9. 使用Spring IoC进行Bean装配

    Spring概述 Spring的设计严格遵从的OCP(开闭原则),保证对修改的关闭,也就是外部无法改变spring内部的运行流程:提供灵活的扩展接口,也就是可以通过extends,implements ...

随机推荐

  1. 【转载】Unity3D研究院之IOS&Andoird使用Sharesdk遇到的坑

    这两天研究了一下ShareSDK,说实话挺好用的,但是还是有点坑的地方.那么雨松MOMO写下博文记录一下来我遇到的坑,嘿嘿. 大部分内容它的文档上已经说的很清楚了. http://wiki.share ...

  2. 求 n的阶乘

    def chengji(n): if n == 0: return 1 return chengji(n-1)*nprint(chengji(n))

  3. cloud-utils

    官方下载:https://launchpad.net/cloud-utils rpm包下载地址:http://rpmfind.net/linux/rpm2html/search.php?query=c ...

  4. A. Vasya and Book

    题目原址 http://codeforces.com/contest/1082/problem/A 题目内容 一共n页书,现在位于第x位,想要看第y页,每次只能翻d页,注意总能翻到第1页和第n页. V ...

  5. Linux静态ip设置及一些网络设置

    网络服务配置文件 /etc/sysconfig/network 网络接口配置文件 /etc/sysconfig/network-scripts/ifcfg-INTERFACE_NAME 修改IP永久生 ...

  6. Android记事本07

    昨天: activity横竖屏切换的生命周期 今天: Anr异常的原因和解决方案 遇到的问题: 无.

  7. DOM关于高度宽度位置的获取

    假设 obj 为某个 HTML 控件. obj.offsetTop 指 obj 相对于版面或由 offsetParent 属性指定的父坐标的计算上侧位置,整型,单位像素. obj.offsetLeft ...

  8. ubuntu服务器环境配置参考

    一.基本的Linux系统命令: ls 查看当前目录下的文件及文件夹 cd /var/www/html 转换目录到/var/www/html cd abc/ddd/ 转换目录到当前目录下的abc文件夹下 ...

  9. 基站选址(base.c/cpp/pas)

    基站选址(base.c/cpp/pas) 题目描述  有N个村庄坐落在一条直线上,第i(i>1)个村庄距离第1个村庄的距离为Di.需要在这些村庄中建立不超过K个通讯基站,在第i个村庄建立基站的费 ...

  10. 过河(DP)

    原题传送门 这道题要用到压缩的思想(原来DP还能这么用...) 其实很简单,假如我们要到某一个位置w 如果我们原位置为Q 很显然,如果(W-Q>=s*t)那么我们一定能到达W 换言之,就是如果我 ...