1, continue above, if you want to inject the bean file, the parameters passed into the constructor function. The main thing to modify is the configuration method in the Spring.xml configuration file.
<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmln S:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:context= "Http://www.springframework.org/schema/context "Xmlns:aop=" HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP "xmlns:tx=" http://www.springframework.org/s Chema/tx "xsi:schemalocation=" Http://www.springframework.org/schema/beans Http://www.sprin Gframework.org/schema/beans/spring-beans-3.0.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/context/spring-context-3.0.xsd Http://www.springfra MEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-3.0.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd "& Gt <bean id= "Do" class= "Com.test.pro.Student" > <constructor-arg value= "+" ></constructor-arg> </bean></beans >
2, we have changed the class into a student class, Student.java, where there is no default constructor, but a new structure with parameters.
Package Com.test.pro;public class Student {private int age;public Student (int.) {this.age=age;} public void Speaking () {System.out.println ("My Age is:" +age);}}
3. Output results
Spring Tutorial Two spring injects a constructor with parameters in XML