I am using Jersey to perform acceptance tests on RESTful web services. It appears as though my applicationContext.xml is not being loaded when the client loads. I see the following log output:
INFO: Using default applicationContext
Is this "default" file soemthing that Jersey loads when it cannot find my file? Or does this indicate that my file was found?
#ContextConfiguration(locations={"/applicationContext.xml", "/applicationContextTest.xml"})
public class BaseResourceTest extends JerseyTest {
final static URI baseUri = UriBuilder.fromUri( "http://localhost" ).port( 9998 ).build();
public BaseResourceTest() throws Exception {
super(new WebAppDescriptor.Builder("xxx.yyy.zzz").contextPath(baseUri.getPath())
.contextParam(
SpringServlet.CONTEXT_CONFIG_LOCATION, "classpath:applicationContextTest.xml" )
.servletClass(SpringServlet.class )
.contextListenerClass( ContextLoaderListener.class )
.build());
}
.......
some tests
.......
}
my web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>xxx.yyy.LoggingAssuranceListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>xxx.yyy.zzzz</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.WadlGeneratorConfig</param-name>
<param-value>xxx.yyy.zzz.BroadsoftWadlGeneratorConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Related
So my head really hurts - I have read about Role/Purpose of ContextLoaderListener in Spring and I cannot go one step further.
I have a really old project and I'm upgrading it. So far I've managed to bring it from spring 2.x to spring 4.x and from Java 7 to Java 8, but I stuck on running application on tomcat 8. It loades ContextLoaderListener twice!? On tomcat 7 starts without problem.
Tomcat 7: apache-tomcat-7.0.29
Tomcat 8: apache-tomcat-8.5.11
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>VERSION-1.7.1</display-name>
<context-param>
<param-name>listenPort_http</param-name>
<param-value>80</param-value>
</context-param>
<context-param>
<param-name>listenPort_https</param-name>
<param-value>8443</param-value>
</context-param>
<context-param>
<param-name>daoType</param-name>
<param-value>ibatis</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>ApplicationResources</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.fallbackLocale</param-name>
<param-value>en</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:META-INF/applicationContext-*.xml
/WEB-INF/applicationContext-*.xml
</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.ERROR_HANDLING</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>
/WEB-INF/faces-specification-config.xml,
/WEB-INF/faces-operating-config.xml,
/WEB-INF/faces-popup-config.xml,
/WEB-INF/faces-mabr-config.xml
</param-value>
<description></description>
</context-param>
<filter>
<filter-name>clickstreamFilter</filter-name>
<filter-class>com.opensymphony.clickstream.ClickstreamFilter</filter-class>
</filter>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter>
<filter-name>rewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter>
<filter-name>exportFilter</filter-name>
<filter-class>org.displaytag.filter.ResponseOverrideFilter</filter-class>
</filter>
<filter>
<filter-name>uploadExtensionsFilter</filter-name>
<filter-class>
org.apache.myfaces.webapp.filter.ExtensionsFilter
</filter-class>
<init-param>
<param-name>uploadMaxFileSize</param-name>
<param-value>10m</param-value>
</init-param>
<init-param>
<param-name>uploadThresholdSize</param-name>
<param-value>100k</param-value>
</init-param>
</filter>
<filter>
<filter-name>compressionFilter</filter-name>
<display-name>Compression Filter</display-name>
<filter-class>org.opendls.webapp.filter.GZIPFilter</filter-class>
</filter>
<filter>
<filter-name>mySecurityFilter</filter-name>
<display-name>Security Filter</display-name>
<filter-class>org.opendls.webapp.filter.MySecurityFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>mySecurityFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>mySecurityFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>clickstreamFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>exportFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>compressionFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>uploadExtensionsFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<listener>
<listener-class>com.opensymphony.clickstream.ClickstreamListener</listener-class>
</listener>
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<listener>
<listener-class>org.opendls.webapp.listener.StartupListener</listener-class>
</listener>
<listener>
<listener-class>org.opendls.webapp.listener.SessionListener</listener-class>
</listener>
<listener>
<listener-class>org.opendls.webapp.listener.ShutdownListener</listener-class>
</listener>
<listener>
<listener-class>org.opendls.webapp.listener.UserCounterListener</listener-class>
</listener>
<servlet>
<servlet-name>faces</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>wsit-jaxws-fromjava</servlet-name>
<display-name>wsit-jaxws-fromjava</display-name>
<description>JAX-WS endpoint - fromjava</description>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>faces</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>wsit-jaxws-fromjava</servlet-name>
<url-pattern>/webservices/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>1440</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>
<error-page>
<error-code>400</error-code>
<location>/index.jsp</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>/403.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/404.jsp</location>
</error-page>
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/viewExpired.jsp</location>
</error-page>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/primary</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/secondary</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
StartupListener.java
public class StartupListener extends ContextLoaderListener
implements ServletContextListener {
private static final Log log = LogFactory.getLog(StartupListener.class);
public void contextInitialized(ServletContextEvent event) {
if (log.isDebugEnabled()) {
log.debug("initializing context...");
}
super.contextInitialized(event);
ServletContext context = event.getServletContext();
String daoType = context.getInitParameter(Constants.DAO_TYPE);
// if daoType is not specified, use DAO as default
if (daoType == null) {
log.warn("No 'daoType' context carameter, using hibernate");
daoType = Constants.DAO_TYPE_HIBERNATE;
}
// Orion starts Servlets before Listeners, so check if the config
// object already exists
Map config = (HashMap) context.getAttribute(Constants.CONFIG);
if (config == null) {
config = new HashMap();
}
// Create a config object to hold all the app config values
config.put(Constants.DAO_TYPE, daoType);
context.setAttribute(Constants.CONFIG, config);
// output the retrieved values for the Init and Context Parameters
if (log.isDebugEnabled()) {
log.debug("daoType: " + daoType);
log.debug("populating ...");
}
setupContext(context);
}
public static void setupContext(ServletContext context) {
ApplicationContext appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
RightsManager rightsManager = (RightsManager) appContext.getBean("rightsManager");
context.setAttribute(Constants.AVAILABLE_ROLES, rightsManager.getAllRights());
if (log.isDebugEnabled()) {
log.debug("initialization complete [OK]");
}
}
}
I have tried many things on web.xml and StartupListener.java but I couldn't manage to load ContextLoaderListener only once. I am getting the same error over and over again:
Error:
27-Jan-2017 02:25:29.217 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath
27-Jan-2017 02:25:30.071 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext
27-Jan-2017 02:25:33.060 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class org.opendls.webapp.listener.StartupListener
java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present - check whether you have multiple ContextLoader* definitions in your web.xml!
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:297)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.opendls.webapp.listener.StartupListener.contextInitialized(StartupListener.java:48)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4725)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5189)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
27-Jan-2017 02:25:33.071 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Closing Spring root WebApplicationContext
27-Jan-2017 02:25:33.075 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Closing Spring root WebApplicationContext
27-Jan-2017 02:25:33.405 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log ContextListener: contextInitialized()
27-Jan-2017 02:25:33.407 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log SessionListener: contextInitialized()
where is the problem?
ok - the problem is resolved
as M.Denim mentioned there were some duplicate listeners which was triggering the same ApplicationContext to load.
There was .tld file in WEB-INF which was containing the same listeners which was in web.xml, the file was created by ant task. A new implementation of Tomcat 8.x read them as noPluggabilityListeners and load was triggered second time.
I'm injecting two beans inside my backing bean with ManagedProperty. The backing bean is view scope and the model bean is request scope that looks like this:
#ManagedBean(name = "categoryBB")
#ViewScoped
public class CategoryBackingBean implements Serializable {
private static final long serialVersionUID = -880184144170934066L;
private static final Logger LOG = Logger
.getLogger(CategoryBackingBean.class);
#ManagedProperty("#{categoryService}")
CategoryService categoryService;
#ManagedProperty("#{categoryBean}")
CategoryBean categoryBean;
//Getters/Setters...
}
However I'm receiving the following error:
javax.servlet.ServletException: Unable to create managed bean categoryBB.
The following problems were found:
The scope of the object referenced by expression #{categoryBean}, request, is shorter than the referring managed beans (categoryBB) scope of view
javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
My web.xml
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-security.xml
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<!-- Enable Spring-Security TagLib in JSF -->
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/springsecurity.taglib.xml</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
Any suggestion?
I have a problem with redirect in Spring MVC. I have a controller with few methods:
//PRINT ALL WORKERS
#RequestMapping("/print")
public String listWorkers(Model model)
{
model.addAttribute("workerList", workerService.getAllWorkers());
return "print";
}
//EDIT WORKER DATA
#RequestMapping("/edit")
public String redirectWorker(HttpServletRequest request)
{
String parameter = request.getParameter("workers");
String path = "redirect:/edit/" + parameter;
return path;
}
#RequestMapping("/edit/{worker}")
public String editWorker(#PathVariable("worker")
String login, Model model)
{
model.addAttribute("worker", workerService.getWorker(login));
return "edition";
}
When I'm using in my program for example method with "print" in request mapping, my URL is:
http://localhost:8080/WWP/print
But when I'm using my method with "edit/{worker}" in request mapping and after that I used method with "print" I got an URL:
http://localhost:8080/WWP/edit/print
Cause my "print" was added after "edit" which isn't necessary. How to return to previous URL:
http://localhost:8080/WWP/print
I suppose that I have to change my RequestMapping annotation. But I don't know how to do this.
EDIT:
Ok, here is my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml, /WEB-INF/spring/appServlet/security.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- Filtry -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
I used the "c:url" in the JSP and it worked.
For example:
It will be remember the previous URL (It's wrong):
My Events
It will be good:
<c:url var="myEventsUrl" value="/events/my" />
My Events
URL is always link to: _http://localhost:8080/WWP/events/my
I am trying to use spring-security
Before all of the configuration
http://localhost:9090/app/login2.xhtml
request, works as i expected.
I added a controller:
#Controller
#RequestMapping("/auth")
public class LoginController {
#RequestMapping(value = "/login", method = RequestMethod.GET)
public String getLoginPage(#RequestParam(value="error", required=false) boolean error,
ModelMap model) {
return "login2.xhtnml";
}
}
I have in web.xml:
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:META-INF/spring-servlet.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
With this configuration when i call
http://localhost:9090/app/login2.xhtml
Error comes
WARN org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/app/login2.xhtml] in DispatcherServlet with name 'spring'
BUT when i change configuration mapping to
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
http://localhost:9090/app/login2.xhtml works as i expected
but
http://localhost:9090/app/auth/login
gives no error, no exception, no redirection, i think dispatcher servlet can not know about this request.
http://localhost:9090/app/app/auth/login
works with
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
My understanding:
dispatcher servlet use "http://localhost:9090/" as base for searching login2.xhtml
and use "http://localhost:9090/app" for /auth/login URL.
I do not know where to set this, and why they are different.
Have you added the SpringSecurityFilterChain to the web.xml?
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Could you past the registered "Request Bindings" if the container starts (from the logfile)?
I am using Apache CXF with Spring , please tell me how the CXFServlet reads the myapp-ws-context.xml
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:myapp-ws-context.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<display-name>CXF Servlet</display-name>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Have you seen sources of org.apache.cxf.transport.servlet.CXFServlet (open source)?
Everything is more than explicit:
#Override
protected void loadBus(ServletConfig sc) {
ApplicationContext wac = WebApplicationContextUtils.
getWebApplicationContext(sc.getServletContext());
String configLocation = sc.getInitParameter("config-location");
if (configLocation == null) {
try {
InputStream is = sc.getServletContext().getResourceAsStream("/WEB-INF/cxf-servlet.xml");
if (is != null && is.available() > 0) {
is.close();
configLocation = "/WEB-INF/cxf-servlet.xml";
}
} catch (Exception ex) {
//ignore
}
}
if (configLocation != null) {
wac = createSpringContext(wac, sc, configLocation);
}
if (wac != null) {
setBus(wac.getBean("cxf", Bus.class));
} else {
setBus(BusFactory.newInstance().createBus());
}
}
Note that WebApplicationContextUtils is a Spring class that tries to find an application context in servlet context attribute named: org.springframework.web.context.WebApplicationContext.ROOT.
Actually your classpath:myapp-ws-context.xml is read by Spring, not CXF.
By adding below configuration in your web.xml, it would be read by Spring and the context would be loaded:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:myapp-ws-context.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
But you could configure your Servlet/WebApp scope of Spring objects, like multipartResolver etc., to make the objects' scopes clearly, by enhancing your CXFServlet configuration like below:
<servlet>
<display-name>CXF Servlet</display-name>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<init-param>
<param-name>config-location</param-name>
<param-value>/WEB-INF/your-webapp-scope-spring-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
*Please take note that from your web-app context, you can access all objects in the context loaded from contextConfigLocation. *