Professional Documents
Culture Documents
@required: This Annotation Makes A Filed Setter Injection Mandatory
@required: This Annotation Makes A Filed Setter Injection Mandatory
mandatory.
package com.app.model;
import org.springframework.beans.factory.annotation.Required;
@Required
public void setVal(Integer val) {
this.val = val;
}
Beans.xml
<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"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.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">
<context:annotation-config></context:annotation-config>
Client Program:
package com.app.test;
import org.springframework.context.ApplicationContext;
import
org.springframework.context.support.ClassPathXmlApplicationCon
text;
import com.app.model.Employee;
ApplicationContext context=new
ClassPathXmlApplicationContext("beans.xml");
Employee
emp=context.getBean("employee",Employee.class);
System.out.println(emp.getVal());