package com.ssh;
public class LoginBiz implements BaseBiz{
private BaseDao loginDao;
public void setLoginDao(BaseDao loginDao){
this.loginDao = loginDao;
}
public void login(){
loginDao.login();
}
}
package com.ssh;
public interface BaseBiz {
public void login();
}
package com.ssh;
public class LoginDao implements BaseDao{
public void login(){
System.out.println("验证");
}
}
package com.ssh;
public interface BaseDao {
public void login();
}
package com.ssh;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.ioc.Print;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
BaseBiz biz = (LoginBiz)context.getBean("loginBiz");
biz.login();
}
}
<bean id="loginDao" class="com.ssh.LoginDao"></bean> <bean id="loginBiz" class="com.ssh.LoginBiz"> <property name="loginDao" ref="loginDao"/> </bean>
原文链接:https://www.f2er.com/javaschema/285606.html