User.java
Package cn.com.xf; Public classUser {PrivateString name; Private intAge ; PrivateString Remark; //Omit Setter/getter Method@Override PublicString toString () {return "User [Name="+ name +", age="+ Age +", remark="+Remark+"]"; }}
Userutil.java
Packagecn.com.xf;//Note the introduction of this packageImportorg.springframework.beans.factory.annotation.Autowired; Public classUserutil {@Autowired//automatic assemblyPrivateuser User; PublicUser GetUser () {returnuser; } Public voidsetUser (user user) { This. user =user; } Public BooleanIsUser () {if(User! =NULL) { return true; } Else { return false; } }}
Spring.xml configuration file
<?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:p= "http://www.springframework.org/schema/p"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd" ><!--The Bean noticed ... -<Beanclass= "Org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" > </bean> <bean id= "User"class= "Cn.com.xf.User" > <property name= "name" value= "Jikoy" ></property> <property name= "Age" va lue= ></property> <property name= "Remark" value= "This is remark245" ></property> </bea n> <bean id= "Userutil"class= "Cn.com.xf.UserUtil" ></bean></beans>
The above has already realized the automatic assembly function, this section has already had the preliminary understanding to the annotation, later we will carry on the thorough study to the annotation.
The test class in this section is the same as the previous sections, the following content, we redefine the class, always user, everyone is tired of it!!!
Spring Series "4" Application @autowired annotations for Bean injection