码迷,mamicode.com
首页 > 编程语言 > 详细

Spring简单属性注入--不常用!!!

时间:2016-05-03 10:28:26      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

UserDAOImpl.java:

package com.bjsxt.dao.impl;

import com.bjsxt.dao.UserDAO;
import com.bjsxt.model.User;

public class UserDAOImpl implements UserDAO {
	/* (non-Javadoc)
	 * @see com.bjsxt.dao.UserDAO#save(com.bjsxt.model.User)
	 */
	
	private int daoId;
	private String daoStatus;
	
	public int getDaoId() {
		return daoId;
	}

	public void setDaoId(int daoId) {
		this.daoId = daoId;
	}

	public String getDaoStatus() {
		return daoStatus;
	}

	public void setDaoStatus(String daoStatus) {
		this.daoStatus = daoStatus;
	}

	public void save(User user) {
		System.out.println("user saved!");
	}
	
	@Override
	public String toString() {
		return this.daoId + ":" + this.daoStatus;
	}
}

bean.xml:

<?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-2.5.xsd">

  <bean name="userDAO" class="com.bjsxt.dao.impl.UserDAOImpl">
  	<property name="daoId" value="8"></property>
  	<property name="daoStatus" value="good"></property>
  </bean>

  <bean id="userService" class="com.bjsxt.service.UserService">
  <!-- 
  	<property name="userDAO">
  		<ref bean="userDAO"/>
  	</property>
  	 -->
  	 <constructor-arg>
  	 	<ref bean="userDAO"/>
  	 </constructor-arg>
  </bean>
</beans>

 

常用方法:

<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  
  <!-- results in a setDriverClassName(String) call -->
  <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  <property name="url" value="jdbc:mysql://localhost:3306/mydb"/>
  <property name="username" value="root"/>
  <property name="password" value="masterkaoli"/>
</bean>

  

 

  

Spring简单属性注入--不常用!!!

标签:

原文地址:http://www.cnblogs.com/wujixing/p/5453920.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!