Saw same issues in others queries, but did not find the answer, hence posting it afresh.
Created a sample Helloworld service in Rest and deployed it in Tomcat-Jersey. Not using Maven. Injecting a spring bean define in applicationContext.xml which is present in WEB-INF directory.
Deployed the service in Tomcat within Eclipse. But when I execute the rest service, cannot find file applicationContext.xml. Once I copy the file to WEB-INF/classes only, it works.
What is the way to make it work by keeping it only in WEB-INF?
web.xml :
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
Rest service code snippet :
ctx = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
It seems reasonable to work when you drop the context descriptor under /WEB-INF/classes because this location is the root of classpath.
So try loading with below uri (without prefix) if you want to drop your applicationContext.xml under WEB-INF folder:
ctx = new ClassPathXmlApplicationContext("/WEB-INF/applicationContext.xml");
Otherwise, can you explain why are you trying to load your applicationContext.xml within your web application?
Alternatively, you can load your application context programatically as follows:
ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
BR.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With