We need four things.
1 Jar 2 Default construction method 3bean.xml add the corresponding statement 4@resource
1 The spring jar packages that are used are listed below
Aspectjrt.jar Aspectweaver.jar Cglib-nodep-2.1_3.jar
Common-annotation.jar Commons-logging.jar
Spring.jar
If you use the JDBC
Also use two jar files
Commons-dbcp.jar
Commons-pool.jar
Mysql-connector-java-5.1.18-bin.jar
Cn.dao [Java] view plain copy <pre name= "code" class= "Java" >package Cn.dao; Public interface Persondaointerface {public abstract void add (); }
Cn.dao.imp
[Java] view plain copy package cn.dao.imp; Import Cn.dao.PersonDaoInterface; public class Persondao implements Persondaointerface {public void Add () {System.out.println ("execute per Sondao.add () "); }} Cn.service
[Java] view plain copy package cn.service; Public interface Personservice {public abstract void Save (); } cn.service.imp
Package cn.service.imp;
Import Javax.annotation.Resource;
Import Org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor;
Import Cn.dao.imp.PersonDao;
Import Cn.service.PersonService;
public class Personservicebean implements Personservice {
private String name;
@Resource private Persondao Persondao;
Public Personservicebean () {} public
Personservicebean (String Name,persondao persondao) {
this.name = name;
This.persondao=persondao;
}
Public String GetName () {return
name;
}
public void SetName (String name) {
this.name = name;
}
Public Persondao Getpersondao () {return
Persondao;
}
public void Setpersondao (Persondao persondao) {
This.persondao = Persondao;
}
public void Save ()
{
persondao.add ();
SYSTEM.OUT.PRINTLN (name);
}
Juintest
[Java] View plain copy package junit.test; import org.junit.test; import org.springframework.context.applicationcontext; import org.springframework.context.support.abstractapplicationcontext; import org.springframework.context.support.classpathxmlapplicationcontext; import cn.service.imp.personservicebean; public class springtest { @Test public