@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());