zoukankan      html  css  js  c++  java
  • bean装配--auto

    1,Dao

    package com.songyan.autoZhuangpei;
    
    public interface UserDao {
        public void say();
    
    }
    package com.songyan.autoZhuangpei;
    
    import org.springframework.stereotype.Repository;
    
    
    public class UserDaoImpl implements UserDao {
        
    public  void say() {
        System.out.println("dao say   ");
    
    }
    }

    2,Service

    package com.songyan.autoZhuangpei;
    
    public interface UserService {
        public void say();
    }
    package com.songyan.autoZhuangpei;
    
    import javax.annotation.Resource;
    
    import org.springframework.stereotype.Service;
    
    
    public class UserServiceImpl implements UserService {
    
        private UserDao userDao;
        
        public UserDao getUserDao() {
            return userDao;
        }
    
        public void setUserDao(UserDao userDao) {
            this.userDao = userDao;
        }
    
        public  void say() {
            userDao.say();
            System.out.println("service   say");
        
        }
    }

    3,Servlet

    package com.songyan.autoZhuangpei;
    
    import javax.annotation.Resource;
    
    import org.springframework.stereotype.Controller;
    
    
    public class UserController {
    
        
        private UserService userService;
        public UserService getUserService() {
            return userService;
        }
        public void setUserService(UserService userService) {
            this.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">
        <bean id="userDao" class="com.songyan.autoZhuangpei.UserDaoImpl" autowire="byName"/>
        <bean id="userService" class="com.songyan.autoZhuangpei.UserServiceImpl"  autowire="byName"/>
        <bean id="userContraller" class="com.songyan.autoZhuangpei.UserController" autowire="byName"/>
        
    </beans>

    5,Test

    package com.songyan.autoZhuangpei;
    
    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/autoZhuangpei/beans6.xml");
            UserController userController=(UserController)applicationContext.getBean("userContraller");
            userController.say();
            
        }
    
    }

    6,结果

  • 相关阅读:
    vue中插槽的理解
    父子组件的通信
    vue3.0怎么禁用eslint校验代码和修改端口号
    三大排序
    让机器人实现自主行走 没你想的那么难
    国内外知名激光雷达公司盘点
    激光雷达寿命短,思岚通过什么技术来解决?
    浅谈SLAM的回环检测技术
    除了ROS, 机器人定位导航还有其他方案吗?
    思岚科技即将登陆“2018日本机器人周”精彩抢先看
  • 原文地址:https://www.cnblogs.com/excellencesy/p/9110532.html
Copyright © 2011-2022 走看看