首页 > 代码库 > spring Setter方法注入
spring Setter方法注入
package entity;public class User { private String id; private String name; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
package dao;public interface UserDao { public void saveUser(); public void getUserById(int id);}
package dao.imp;import dao.UserDao;public class UserDaoImp implements UserDao{ @Override public void saveUser() { // TODO Auto-generated method stub System.out.println("--------save user------"); } @Override public void getUserById(int id) { // TODO Auto-generated method stub }}
package service;public interface UserService { public void saveUser(); public void getUserById(int id);}
package service.imp;import dao.UserDao;import service.UserService;public class UserServiceImp implements UserService{ private UserDao userDao; public UserDao getUserDao() { return userDao; } public void setUserDao(UserDao userDao) { this.userDao = userDao; } @Override public void saveUser() { // TODO Auto-generated method stub System.out.println("SAVE USER"); } @Override public void getUserById(int id) { // TODO Auto-generated method stub }}
package action;import service.UserService;public class UserAction {private UserService userService;public UserService getUserService() { return userService;}public void setUserService(UserService userService) { this.userService = userService;}public String saveUser(){ userService.saveUser(); return null;}}
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="userDao" class="dao.imp.UserDaoImp"></bean><bean id="userService" class="service.imp.UserServiceImp"><property name="userDao" ref="userDao"></property></bean><bean id="userAction" class="action.UserAction"><property name="userService" ref="userService"></property></bean></beans>
spring Setter方法注入
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。