0% found this document useful (0 votes)
12 views2 pages

@autowired On Setter Methods

The document provides a Java implementation using Spring Framework's dependency injection with the @Autowired annotation on setter methods. It defines two classes, Employee and Company, where Employee has a setter method for injecting a Company instance. The MainApp class initializes the application context and retrieves the Employee bean to demonstrate the functionality of the injected Company instance.

Uploaded by

aayushg030
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

@autowired On Setter Methods

The document provides a Java implementation using Spring Framework's dependency injection with the @Autowired annotation on setter methods. It defines two classes, Employee and Company, where Employee has a setter method for injecting a Company instance. The MainApp class initializes the application context and retrieves the Employee bean to demonstrate the functionality of the injected Company instance.

Uploaded by

aayushg030
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

@Autowired on Setter Methods :

● [Link]
package [Link];
import [Link];
public class Employee
{
private Company com;
@Autowired
public void setCompany( Company com )
{
[Link] = com;
}
public Company getCompany( )
{
return com;
}
public void Area()
{
[Link]();
}
}

● [Link]
package [Link];
public class Company
{
public Company()
{
[Link]("Inside Company constructor." );
}
public void printArea()
{
[Link]("Hinjewadi Pune" );
}
}

● [Link]
package [Link];
import [Link];
import [Link];
public class MainApp
{
public static void main(String[] args)
{
ApplicationContext con = new ClassPathXmlApplicationContext("[Link]");

Employee e = (Employee) [Link]("emp");


[Link]();
}
}

● [Link]
<?xml version = "1.0" encoding = "UTF-8"?>
<beans>
<context:annotation-config/>
<bean id = "emp" class = "[Link]">
</bean>
<bean id = "com" class = "[Link]">
</bean>
</beans>

You might also like