In my web application, I am not using applicationContext.xml
. How can I get the bean of @Service
annotated class?
If I used the applicationContext.xml
in my web application, I have to load the applicationContext.xml
every time to get the bean of the @Service
annotated class.
I used this way
WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext);
ServerConnection con = (ServerConnection ) ctx.getBean("con");
My Service class will be as ,
@Service or @Service("con")
public class ServerConnection {
private TServerProtocol tServerProtocol;
private URI uri;
public TServerProtocol getServerConnection(){
System.out.println("host :"+host+"\nport :"+port);
try {
uri = new URI("tcp://" + host + ":" + port);
} catch (URISyntaxException e) {
System.out.println("Exception in xreating URI Path");
}
tServerProtocol = new TServerProtocol(new Endpoint(uri));
return tServerProtocol;
}
}
Is there any other way to get a bean of this class ?
or
What is the proper way to get a bean of @Service
annotated class in case of core application and web application in Spring3.x?