Hi
I am running WebSphere application server 9 (Java 1.8) which hosts a JAX-RS application and would like to inject spring beans ( Spring-Core version 5.3.27) into the application.
Since websphere JAX-RS depends on IBMRestServlet, following the reference http://www.javavillage.in/spring-ioc-on-servlets.php, I tried creating a class that extends the IBMRestServlet and adding in an init() like one below
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
}
I had to add in was_public.jar and j2ee.jar provided in the WebSphere Dev folder as "provided" dependency in maven but maven was still complaining about following
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] cannot access com.ibm.ws.ras.instrument.annotation.InjectedFFDC
class file for com.ibm.ws.ras.instrument.annotation.InjectedFFDC not found
I was not able to resolve the dependency. I searched IBM resources for a solution but could not find any. Greatly appreciate if anyone can guide me here or suggest a better approach
In meanwhile, I tried the following alternate method
Alternate Method : Load Spring within Resource Class
I tried loading spring context within the resource class and was successfully able to use Spring beans
@Component
@Path("/mypath")
public class MyResource {
@Autowired
TestClass testClass;
@POST
@Path("/subpath")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getSomeWork(MyRequest request) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
TestClass tClass = applicationContext.getBean(TestClass.class);
..
}
the Web.xml needed the following
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/webApplicationContext.xml</param-value>
</context-param>
Unfortunately as it is obvious, there would be a big overhead of the initialization per resource along with having multiple Spring ApplicationContext ( one per resource) for the application which is undesirable
Thanks in advance
Sibi
------------------------------
Sibi Vaithara
------------------------------