Spring-ws on Weblogic: MessageDispatcherServlet doesn't have a default constructor - weblogic-10.x

I'm trying to deploy a war containing spring webservices. But I am getting a weird error like this:
following error weblogic.application.ModuleException: [HTTP:101216]Servlet: "spring-ws" failed to preload on startup in Web application: "myApp-1.0.0-SNAPSHOT.war".
javax.servlet.ServletException: Servlet class: 'org.springframework.ws.transport.http.MessageDispatcherServlet' doesn't have a default constructor
at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:261)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.StubSecurityHelper.createServlet(StubSecurityHelper.java:64)
at weblogic.servlet.internal.StubLifecycleHelper.createOneInstance(StubLifecycleHelper.java:58)
at weblogic.servlet.internal.StubLifecycleHelper.<init>(StubLifecycleHelper.java:48)
at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:539)
at weblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletContext.java:1976)
at weblogic.servlet.internal.WebAppServletContext.loadServletsOnStartup(WebAppServletContext.java:1950)
I've tried giving a default constructor in the endpoint class.
Below are the steps which I followed:
web.xml has this entry:
<servlet>
<servlet-name>spring-ws</servlet-name>
<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
<init-param>
<param-name>transformWsdlLocations</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-ws</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
web-inf folder has spring-ws-servlet.xml file which has the entries for component scan, enabling the annotations and the wsdl entry like this:
<sws:static-wsdl id="MyService"
location="classpath:/services/myService/1.0/MyService.wsdl" />
Please let me know if I'm missing anything here....
Thank you.

It is likely that the jar files Weblogic is using to initialize the Spring classes and those expected to be used are in conflict.
To force the Weblogic container to use the jar files bundled with the war file you have to specify a WEB-INF/weblogic.xml file with the following content
<weblogic-web-app>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>
see this thread

Related

importing XML config into java config based (annotation) project

I'm working on Spring MVC annotation based application. I have web.xml file entry as follows (using WebConfig.java for configuration):
<servlet>
<servlet-name>sdsdispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.conf.WebConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Now when I try to integrate security related XML file I'm facing following error
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:638)
I tried to import xml file as follows:
#Configuration
#EnableWebMvc
#ComponentScan("com.stk.controller")
#ImportResource({"securityContext.xml"})
public class WebConfig extends WebMvcConfigurerAdapter {
Screenshot
http://i.stack.imgur.com/BosWG.jpg
Add classpath as shown below, provided its in classpath
#ImportResource("classpath:securityContext.xml")
If you have multiple configuration files then
#ImportResource(locations={"classpath:securityContext.xml","file://c:/test-config.xml"})
You can access the file from WEB-INF directory using
#ImportResource("file:**/WEB-INF/securityContext.xml")
However I would recommend you to move configuration file to src/main/resource directory and use the file line that is loading file using classpath. These files will be copied to WEB-INF/classes directory during packing of war by maven which is classpath

How to set Spring root context path

I am a Spring newbie and am putting together a Spring web-app (not Spring-boot - how much difference does this make?). Deployment is on a Tomcat 7 server.
The app is up and running. My problem is that is only accessible via the standard URL:
http://mycompany.com:8081/cwing-0.0.3-SNAPSHOT/index.html
The following do not work:
http://mycompany.com:8081/cwing-0.0.3-SNAPSHOT
http://mycompany.com:8081/cwing-0.0.3-SNAPSHOT/
even though my web.xml lists index.html as the welcome page.
An additional symptom of the problem is that all sorts of links within the application need to be specified as relative, rather than with a prepended '/'.
But even these urls are not what I really want.
I would rather specify
http://mycompany.com:8081/cwing
and have it bring up the index.html.
Following the lead of Add context path to Spring Boot application
I created an application.xml file in src/main/resources with the following content:
server.contextPath=/cwing
server.port=8081
This doesn't work. http://mycompany.com:8081/cwing brings up a blank page, with a 404 error on the server, as does http://mycompany.com:8081/cwing/index.html.
I must be missing something. What else is needed to get this to work as I want it to work?
UPDATE: as asked, here is the web.xml (irrelevant details removed).
<?xml version="1.0"?>
<web-app 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_3_0.xsd"
version="3.0">
<display-name>cwing</display-name>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 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/context.xml
/WEB-INF/spring/datasource.xml
/WEB-INF/spring/security.xml
</param-value>
</context-param>
<servlet>
<servlet-name>d</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/context.xml
/WEB-INF/spring/datasource.xml
/WEB-INF/spring/security.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>d</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<!-- Disables Servlet Container welcome file handling. Needed for compatibility
with Servlet 3.0 and Tomcat 7.0 -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<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>
This is not related to Spring MVC but to specific server, by default Tomcat gets your WAR name as context root. If you want to change this, you can always rename your WAR file or I recommends to change your pom.xml to build your WAR file with final name, here is how to do this:
<build>
<finalName>finalName</finalName>
. . .
</build>

Idea tomcat run configuration cannot find xml files of spring

I am using local tomcat server run configuration in idea. My code works just fine if I deploy it to the server through manager. However if I run it on idea it gives the following error :
java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]
I have this setting in web.xml :
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I have my mvc-dispatcher-servlet.xml in src/main/webapp/WEB-INF folder. What could be causing this?
Spring MVC looks for a file named [servlet-name]-servlet.xml in the WEB-INF directory of your web application and creates the beans defined there, overriding the definitions of any beans defined with the same name in the global scope.
See this link
The file name must be mvc-dispatcher-servlet.xml and not mvc-dispather-servlet.xml.

Servlets in Maven

In the Maven Webapp project, I created the servlet DiaServlet in the root directory of the project, i.e., the directory where pom.xml is.
Its description in web.xml is as follows:
<servlet>
<servlet-name>DiaServlet</servlet-name>
<servlet-class>DiaServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DiaServlet</servlet-name>
<url-pattern>/DiaServlet</url-pattern>
</servlet-mapping>
To this, I am getting the error:
java.lang.ClassNotFoundException: DiaServlet
One thing I tried is changing <servlet-class> tag to
<servlet-class>Prj.base.DiaServlet</servlet-class>
Here, Prj.base is the groupId of the project in the pom.xml file-- if this would be any concern(?)
<groupId>Dia.base</groupId>
The same servlet web.xml definition worked as is in a "non-Maven" web application.
When I created the servlet (I'm using NetScape), the servlet description wasn't added to the web.xml file although I'd checked to add it automatically.
Is this a problem of the build environment, or my servlet definition in web.xml (if so, how come the same definition worked in the other web application?) or something else?
new to Maven
TIA
You are a maven user, at the time of initialization of your project, you are giving package name as Dia.base, so your classes are resides in the Dia.base package only
So,
<servlet>
<servlet-name>DiaServlet</servlet-name>
<servlet-class>Dia.base.DiaServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DiaServlet</servlet-name>
<url-pattern>/DiaServlet</url-pattern>
</servlet-mapping>
you need to give the fully qualified class name in the <servlet-class>

deploying and running embedded mule in webapp (Mule twitter integration)

Hi I am newbaby to Mule!!
I want to run this simple app (receives input from url and post to my twitter account using twitter connector).
I try first deploying it on CloudHub and it works http://twitterconnector.cloudhub.io/addtweet?mymessage=firsttweet
after that I wanted to try deploying on Tomcat so I created simple webapp using maven and put all required dependences for Mule in pom.xml, set web.xml and mule-config.xml files and when I go to localhost:8181/easymule-test/services/addtweet?mymessage=firsttweet it is not working!
Can someone pls help/explain what is the problem?
than you in advance!!
Here is the flow:
<flow name="twitterconnectorFlow1" doc:name="twitterconnectorFlow1">
<servlet:inbound-endpoint path="addtweet" responseTimeout="10000" doc:name="Servlet"/>
<twitter:update-status config-ref="test_ECAccount" status="#[header:INBOUND:mymessage]" doc:name="Twitter Connector"/>
<expression-transformer evaluator = "groovy" expression="payload.toString()" returnSourceIfNull="true" doc:name="Expression"/>
</flow>
Edit: web.xml configuration fragment
<web-app>
<display-name>easymule-test</display-name>
<context-param>
<param-name>org.mule.config</param-name>
<param-value>/WEB-INF/muleconfig.xml</param-value>
</context-param>
<listener>
<listener-class>org.mule.config.builders.MuleXmlBuilderContextListener</listener-class>
</listener>
<servlet>
<servlet-name>ajax</servlet-name>
<servlet-class>org.mule.transport.ajax.container.MuleAjaxServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>muleServlet</servlet-name>
<servlet-class>org.mule.transport.servlet.MuleReceiverServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>muleResources</servlet-name>
<servlet-class>org.mule.transport.ajax.MuleJarResourcesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>muleServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>muleResources</servlet-name>
<url-pattern>/mule-resource/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ajax</servlet-name>
<url-pattern>/ajax/*</url-pattern>
</servlet-mapping>
</web-app>
A servlet endpoint path is a path not an address, so use:
<servlet:inbound-endpoint path="sendtweet" ...
Assuming:
your web-app is deployed on the /easymule-test context,
and is running on port 8181
and the org.mule.transport.servlet.MuleReceiverServlet is bound to the services path
then you'll access the above endpoint at http://localhost:8181/easymule-test/services/sendtweet.

Resources