How do I migrate from Jersey 1.0 to Jersey 2.0? - maven
I'm trying to upgrade to Jersey 2.0 and I'm having a lot of trouble because the groupIds and artifactIds of Jersey have completely changed and I can't find a migration plan in the Jersey docs.
Here's what my pom.xml used to look like, and this compiled fine:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.17</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>1.17</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server-linking</artifactId>
<version>1.17.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.17.1</version>
</dependency>
What should these be changed to? This unrelated StackOverflow question was somewhat helpful, but I'm having trouble finding things like where the #Ref annotation moved to.
Update
It seems that #Ref no longer exists or at least it's not mentioned in the documentation anymore. Now you use a UriBuilder.
I found a very helpful section in the documentation that answers my maven issues.
The HTTPBasicAuthFilter has been renamed to HttpBasicAuthFilter. Notice the capitalization.
Client client = Client.create(); has become Client client = ClientBuilder.newClient();
This:
String json = client
.resource(getBaseUrl() + url)
.accept(MediaType.APPLICATION_JSON_TYPE)
.get(String.class);
has become
String json = client
.target(getBaseUrl())
.path(url)
.request(MediaType.APPLICATION_JSON_TYPE)
.get(String.class);
You don't.
Jersey 2.0 is missing a lot of functionality from Jersey 1.0. Contrary to what the committers will tell you, some things are plain impossible to implement right now (e.g. Guice, Spring integration). Things appear to work on the surface, but once you dig in deeper you will find a lot of features are still broken.
Many of the 1.x plugins do not exist in 2.x, mainly because of the aforementioned breakage.
In light of this, I suggest a holding off on Jersey 2.x for the foreseeable future. Hopefully the committers will clean this up in the coming year.
It is pain in the neck I have to say.
We are currently knee deep into migrating relatively large 3+ years old client-server project and boy do I want to bite my neck off.
Hopefully we are at the end of the struggle...
While there is a migration guide indeed it is not comprehensive by any means.
UniformInterfaceException (and others) is no more.
Instead it is replaced by WebApplication exception and successors. There is not a word about that in the migration guide and this is very very important.
JSON support
The migration guide says:
JSON Support has undergone certain changes in Jersey 2.x. The most
visible difference for the developer is in the initialization and
configuration.
In Jersey 1.x, the JAXB/JSON Support was implemented as a set of
MessageBodyReaders and MessageWriters in the jersey-json module.
Internally, there were several implementations of JSON to Object
mapping ranging from Jersey's own custom solution to third party
providers, such as Jackson or Jettison. The configuration of the JSON
support was centralized in the JSONConfiguration and JSONJAXBContext
classes.
Great. What if you have chosen the "Jersey's own custom solution" (which we did for whatever reason)? There is no alternative to that in jersey 2. I tried to produce the same JSON format using Jettison, Jackson and Moxy providers. I did not succeed. For reference, my unanswered question here: Jersey 2 JSON Jettison unwrapping root element
See the 1.x to 2.0 migration guide in the Jersey docs. (2019 link to 1.x to 2.0 migration guide)
It looks like #InjectLink is the replacement for #Ref.
From that link, I was able to drop this into my pom.xml:
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-declarative-linking</artifactId>
<version>2.6</version>
</dependency>
and then I took an existing #Ref and was able to drop in replace with #InjectLink.
public Long id; // This id is referenced below in the link
#InjectLink(resource = FavoriteResource.class, method = "updateFavorites", bindings = {
#Binding(name = "listId", value = "${instance.id}")
})
public URI linkURI;
It looks like some of the JavaDocs from #Ref are in #InjectLink even, which would be further confirmation that it's the replacement:
/**
* ...
* #Ref(resource=SomeResource.class)
* #Ref(resource=SomeResource.class, bindings={
* #Binding(name="id" value="${instance.id}"}
* )
*/
EDIT:
Tricky stuff. I needed one more piece to make this work for me. In web.xml,
I now have:
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.mycompany.root</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>com.mycompany.root.web.filter.AuditResourceFilterFactory;com.mycompany.root.web.filter.OtherAuditResourceFilterFactory</param-value>
</init-param>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.mycompany.root.web.resource.config.CustomResourceConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
and finally, CustomResourceConfig.java looks like this
import org.glassfish.jersey.linking.DeclarativeLinkingFeature;
import org.glassfish.jersey.server.ResourceConfig;
public class CustomResourceConfig extends ResourceConfig {
public CustomResourceConfig() {
packages("org.glassfish.jersey.examples.linking");
register(DeclarativeLinkingFeature.class);
}
}
You can follow following steps for migration from Jersey 1 to Jersey 2 :
Add following dependencies in POM file :
Jersey 2.23.2 dependencies
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.23.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring3</artifactId>
<version>2.23.2</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.23.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.23.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-entity-filtering</artifactId>
<version>2.23.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.23.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.23.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.bundles.repackaged</groupId>
<artifactId>jersey-guava</artifactId>
<version>2.23.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.23.2</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.5.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.23.2</version>
</dependency>
<dependency>
<groupId>org.jvnet</groupId>
<artifactId>mimepull</artifactId>
<version>1.6</version>
</dependency>
Make Following entry in Web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" 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">
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.jsg.resource.initializer.RestResourceInitializer</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping> '
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/myAppName</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
Write following code in RestResourceIntializer
package com.jsg.resource.initializer;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
public class RestResourceInitializer extends Application {
/**
* Gets the classes.
*
* #return the classes
*/
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<Class<?>>();
// Resources
classes.add(org.glassfish.jersey.jackson.JacksonFeature.class);
classes.add(org.glassfish.jersey.server.spring.scope.RequestContextFilter.class);
classes.add(org.glassfish.jersey.media.multipart.MultiPartFeature.class);
//Rest classes within Application.
classes.add(com.jsg.rest.AbcRestService.class);
classes.add(com.jsg.rest.CdeRestService.class);
return classes;
}
}
Now if you will deploy code with above changes on websphere,you will get following exception :
Caused by: java.lang.NoSuchMethodError: javax/ws/rs/core/Application.getProperties()Ljava/util/Map; at org.glassfish.jersey.server.ApplicationHandler.(ApplicationHandler.java:287) at org.glassfish.jersey.servlet.WebComponent.(WebComponent.java:311)
Reason for above exception is that,Websphere supports JAX-RS 1 implementation,however we are deploying Jersey 2 code which is Jax-rs 2 implementation.
Steps for resolving above exception:
So basically what we have to do is to force WebSphere to pick our Jersey 2 jars instead of default Jax-rs 1.We need to follow following steps for that
1) Disable in built JAX-RS by setting following JVM property to true
com.ibm.websphere.jaxrs.server.DisableIBMJAXRSEngine=true
This property can be set through admin console of WebSphere by going to Servers->All Server -> ->Server Infrastructure -> Java and Process Management ->Process Deifinition ->Additional Properties-> Java Virtual Machine ->Additional Properties-> Custom Properties
2) Create Isolated Shared Library having the Jersey 2 Jars and Spring 4 Jars
Isolated shared library can be created through admin Console of Websphere by going to Environment-> Shared Libraries ->New
n the classpath box,we need to enter path of the folder on the server,where we have placed all Jersey 2 and Spring 4 Jars
/var/was/server2/jerseyLib1/spring-context-4.3.4.RELEASE.jar
/var/was/server2/jerseyLib1/spring-core-4.3.4.RELEASE.jar
/var/was/server2/jerseyLib1/spring-beans-4.3.4.RELEASE.jar
/var/was/server2/jerseyLib1/spring-aop-4.3.4.RELEASE.jar
/var/was/server2/jerseyLib1/spring-web-4.3.4.RELEASE.jar
/var/was/server2/jerseyLib1/spring-expression-4.3.4.RELEASE.jar
/var/was/server2/jerseyLib1/spring-bridge-2.5.0-b05.jar
/var/was/server2/jerseyLib1/hk2-locator-2.5.0-b05.jar
/var/was/server2/jerseyLib1/hk2-api-2.5.0-b05.jar
/var/was/server2/jerseyLib1/hk2-utils-2.5.0-b05.jar
/var/was/server2/jerseyLib/javax.inject-2.5.0-b05.jar
/var/was/server2/jerseyLib1/javax.annotation-api-1.2-b03.jar
/var/was/server2/jerseyLib1/javax.ws.rs-api-2.0.1.jar
/var/was/server2/jerseyLib1/jersey-client-2.23.2.jar
/var/was/server2/jerseyLib1/jersey-spring3-2.23.2.jar
/var/was/server2/jerseyLib1/jersey-container-servlet-core-2.23.2.jar
/var/was/server2/jerseyLib1/jersey-server-2.23.2.jar
/var/was/server2/jerseyLib1/jersey-common-2.23.2.jar
/var/was/server2/jerseyLib1/jersey-guava-2.23.2.jar
Also in class loading section ,select "use an isolated class loader for this shared library"
and then finally click on Apply and Ok and we are done with creation of isolated shared library.
Bind this isolated shared library with your application war file as follows in admin Console
a) Application -> All Applications -> Click on your application name
b) Go to References -> Shared Library References -> Reference Shared Libraries ->select your application war(Not ear) and click ok.
c) Select the library that we created in Step 2 in "Available" combo box on left side and put it on right side in "Selected" combo box and click ok.
With this we have associated the isolated shared library with application war file.
Restart Server and application should be up and running.
Related
Tomcat 6 vs 7 broke default and jsp servlet requests (404)
We're migrating around 20 web contexts from Tomcat 6.0.48 to Tomcat 7.0.76 but we're facing an issue with the requests handled by the servlets configured in the parent web.xml (tomcat7\conf\web.xml). The problem is that requests for /some_file.html, /some_file.jsp, /images/some-image.jpg, /index.xhtml return a 404 NOT FOUND, while other custom servlets declared in the web.xml of the context work fine. All 20 contexts are working fine in Tomcat 6 for years, but only 10 are failing on Tomcat 7. We have compared the ones that work with the ones that don't, but they are very different (unsurprisingly) and we haven't found the problem. The tests Projects are deployed using Eclipse under Windows, some test were executed deploying the WAR file directly on /webapps with the same results. All projects are Java 1.8 and they are mavenized. The tests consist in deploying one working context and one that does not work and navigate to: /some_file.html, /some_file.jsp, /images/some-image.jpg and see if the response is 200 or 404. We've tried to match the version of javax.servlet.servlet-api (2.5 to 3.0.1) and javax.servlet.jsp.jsp-api (2.0 to 2.2) with the ones provided by Tomcat 7 in the dependencies (Parent POM). No change. <dependency> <groupId>javax.servlet</groupId> <!-- <artifactId>servlet-api</artifactId> <version>2.5</version> --> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <!-- <version>2.0</version> --> <version>2.2</version> <scope>provided</scope> </dependency> We've copied the default and jsp servlet mapping configuration from the web.xml file of Tomcat on the web.xml of the application. No change. <!-- The mapping for the default servlet --> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- The mappings for the JSP servlet --> <servlet-mapping> <servlet-name>jsp</servlet-name> <url-pattern>*.jsp</url-pattern> <url-pattern>*.jspx</url-pattern> </servlet-mapping> We've changed the url-pattern / to /* in the tomcat's web.xml file for the default servlet and things started to work with static resources but not for *.jsp and *.xhtml files (Faces). But as read in the servlet specification (JSR-315), it should work with /. Either way, this change broke *.jsp requests for all contexts (¿?). <servlet-name>default</servlet-name> <url-pattern>/</url-pattern> <servlet-name>default</servlet-name> <url-pattern>/*</url-pattern> We've deleted all servlet-mapping and filter-mapping from the web.xml file of the context to see if there was any kind of conflict. No change. We suspect that... either the tomcat's web.xml is not read, it's overwritten, or the url-pattern for / and *.jsp is broken by some contexts's descriptor. Any clues? Thanks in advance.
Restful site broke after upgrading resteasy-jaxrs to the lastest version
I'm going through this tutorial example on RestEasy: http://www.mkyong.com/webservices/jax-rs/resteasy-hello-world-example/ I downloaded their code and made modification so that I can deploy it to tomcat 7 and java 1.7. If I leave the pom.xml as specified by the site, <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-jaxrs</artifactId> <version>2.2.1.GA</version> </dependency> then everything appears to be fine and can be accessed through: http://localhost:8080/RESTfulExample/rest/message/hello However, if I were to increase the version level to 3.0.8.Final or "RELEASE", <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-jaxrs</artifactId> <version>3.0.8.Final</version> </dependency> then I can't access it via the above URL. Instead, I get this message in my localhost_access_log.txt 127.0.0.1 - - [19/Aug/2014:16:02:55 -0700] "GET /RESTfulExample/rest/message/hello HTTP/1.1" 404 - Question: Does anyone know how I can get the pom.xml to work if I really want to use RESTeasy 3.0.8.Final? I'm new to Rest. Thanks in advance.
As the documentation describes you can initialize RESTeasy in a standalone Servlet 3.0 compliant container by adding this dependency: <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-servlet-initializer</artifactId> <version>3.0.8.Final</version> </dependency> You should also update the web.xml with the correct Servlet version. Most of the old configuration stuff can be removed so you end up with: <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>Restful Web Application</display-name> </web-app> Last thing to do is tell RESTeasy on which path you want to map your application by adding javax.ws.rs.ApplicationPath to the MessageApplication class: #ApplicationPath("/rest") public class MessageApplication extends Application { ... }
Zest 1.1.0 cannot integrate with ZK 6.5.2
I am using ZK framework version 6.5.2 for my application. And now I want to integrate RESTful to it by using Zest. The problem is, the latest version of Zest is 1.1.0, and it depends on zcommon-5.0.0. So this dependency (zcommon-5.0.0) is duplicated and I excluded it from my POM file, like this: <dependency> <groupId>org.zkoss.zest</groupId> <artifactId>zest</artifactId> <version>1.1.0</version> <exclusions> <exclusion> <groupId>org.zkoss.common</groupId> <artifactId>zcommon</artifactId> </exclusion> <exclusion> <groupId>org.zkoss.common</groupId> <artifactId>zweb</artifactId> </exclusion> </exclusions> </dependency> As a result zest now depends on zcommon-6.5.2. When I start my app, an error occured: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to org.zkoss.xel.taglib.FunctionDefinition at org.zkoss.xel.taglib.Taglibs.getFunctionMapper(Taglibs.java:150) at org.zkoss.xel.taglib.Taglibs.getFunctionMapper(Taglibs.java:109) at org.zkoss.zest.sys.impl.ParserImpl.parse(ParserImpl.java:97) at org.zkoss.zest.sys.impl.ParserImpl.parse(ParserImpl.java:54) at org.zkoss.zest.sys.ZestManager.loadConfiguration(ZestManager.java:98) at org.zkoss.zest.sys.ZestManager.init(ZestManager.java:70) at org.zkoss.zest.sys.ZestFilter.init(ZestFilter.java:74) Here is my web.xml: <filter> <filter-name>zest</filter-name> <filter-class>org.zkoss.zest.sys.ZestFilter</filter-class> <!-- specifies the class name of the ZEST manager to handle actions Default: org.zkoss.zest.sys.ZestManager --> <init-param> <param-name>manager-class</param-name> <param-value>org.zkoss.zest.sys.ZestManager</param-value> </init-param> <!-- specifies the class name of the parser used to parse the configuration file (WEB-INF/zest.xml). Default: org.zkoss.zest.sys.impl.ParserImpl --> <init-param> <param-name>parser-class</param-name> <param-value>org.zkoss.zest.sys.impl.ParserImpl</param-value> </init-param> </filter> And here is rest definition in zest.xml: <?xml version="1.0" encoding="UTF-8"?> <zest> <xel-method prefix="c" name="toMethodName" class="com.myapp.view.RestAction" signature="java.lang.String toMethodName(java.lang.String)"/> <action path="/rest" method="${c:toMethodName(request.method)}" class="com.myapp.view.RestAction"> <result>/WEB-INF/index.zul</result> </action> </zest> I have compared the source code of these 2 files Taglibs.java in version 5.0.0 and 6.5.2 of zcommon and realized that they have so many differences. I think that the reason caused above problems (the initialization process has changed from 5.0.5 to 6.5.2). Could you please help me solve this problem so that I can integrate zest to my ZK application? Thank you so much.
Zest 1.1 is not compatible with ZK 6.5.2. You have to upgrade to Zest 2.0: http://mavensync.zkoss.org/maven2/org/zkoss/zest/zest/2.0.0.FL.20130205/
Why isn't there the "net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter" class in ehcache2.6 package?
I want to try the page caching. But I coundn't find the net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter class, so I get a error that is class not found What should I do? <filter> <filter-name>SimplePageCachingFilter</filter-name> <filter-class>net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter </filter-class> </filter>
SimplePageCachingFilter was moved out of the core Ehcache jars already some time ago (IIRC) and it's now part of ehcache-web, add a dependency to it e.g. via maven: <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache-web</artifactId> <version>2.0.4</version> </dependency>
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
i am using spring 3.1.0.RELEASE, and my servlet container is tomcat 7 and my IDE is eclipse indigo and the jar spring-webmvc-3.1.0.RELEASE.jar which contains the DispatcherServlet exists in the lib folder, and yet when running the application, i am getting the exception: java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523) at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:525) at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:507) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:126) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1043) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4957) at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5284) at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5279) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) please advise why i am getting this exception, and how to fix it. EDIT: following are my configuration files: 1- .springBeans: <?xml version="1.0" encoding="UTF-8"?> <beansProjectDescription> <version>1</version> <pluginVersion><![CDATA[2.9.0.201203011806-RELEASE]]></pluginVersion> <configSuffixes> <configSuffix><![CDATA[xml]]></configSuffix> </configSuffixes> <enableImports><![CDATA[false]]></enableImports> <configs> <config>src/main/webapp/WEB-INF/checkout-servlet.xml</config> </configs> <configSets> </configSets> </beansProjectDescription> 2- web.xml: <web-app> <display-name>Checkout</display-name> <servlet> <servlet-name>checkout</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>checkout</servlet-name> <url-pattern>*.action</url-pattern> </servlet-mapping> </web-app> 3- checkout-servlet.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> <context:component-scan base-package="com.myapp"/> <bean id="myService" class="com.myapp.MyService"/> </beans> also when trying to access any page in the application, i get the exception: HTTP Status 404 - Servlet checkout is not available type Status report message Servlet checkout is not available description The requested resource (Servlet checkout is not available) is not available. Apache Tomcat/7.0.22
You need to add the "Maven Dependency" in the Deployment Assembly right click on your project and choose properties. click on Deployment Assembly. click add click on "Java Build Path Entries" select Maven Dependencies" click Finish. Rebuild and deploy again Note: This is also applicable for non maven project.
Two possible answers: 1- You did not include spring-beans and spring-context jars in your lib. If you are using maven (which will help a lot) those two lines will be enough <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>3.1.0.RELEASE</version> </dependency> 2- The necessary jars are in your classpath but are not deployed on tomcat.
I had the same problem with Idea Intellij and Spring 4. I fixed the problem and I wanted to share the answer with you. I use tomcat 7 / idea intellij 13 / spring 4. pom.xml dependencies: <properties> <spring.version>4.0.5.RELEASE</spring.version> </properties> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> enter code here <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.2</version> </dependency> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.4</version> </dependency> </dependencies> In idea Intellij, you need to go to File -> Project Settings -> Artifacts. Then clean -> rebuild the project -> build the artifact, and everything will be ok.
This solves the problem for me. It's easy and pretty simply explained. Step 1 Right click on project Click on Properties Step 2 Click on Deployment Assembly Tab in the Click Add... Step 3 Click on Java Build Path Entries Step 4 Click on Maven Dependencies Click Finish button Step 5 Redeploy Spring MVC application to Tomcat again Restart Tomcat List item classnotfoundexception
i found that in the deployment assembly, there was the entry: [persisted container] org.maven.ide.eclipse.maven2_classpath_container i removed it, and added the maven dependencies entry, and it works fine now.
If all of these advice doesn't work, you should re-create your Server (Tomcat or like that). That solved my problem.
Include below dependency in your pom.xml <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>{spring-version}</version> </dependency>
I was facing the same Issue. When I saw into maven repository .m2 folder(....m2\repository\org\springframework\spring-webmvc) in my local I found two 3.2.0.RELEASE folders. SO I removed one. Then I went to project, right click->properties->deployment essembly-> add maven dependencies. clean build and then restart the server. Then the DispatcherServlet got loaded.
Go to properties of Project which your working Choose the Deployment Assembly menu and Click on add button opt the Java Build Path Entries and Click on Maven Dependencies Build the project and run
In my case I get this trouble after using the maven's update project utility. I tried all the workarounds you suggested but nothing seemed to work. At the end the solution was simply to remove the project from the server to ensure that it was clean, and add it again. Then it works, I hope this solution could help any of you.
You can use GlassFish server and the error will be resolved. I tried with tomcat7 and tomcat8 but this error was coming continuously but resolved with GlassFish. I think it's a problem with server. These are the results with tomcat7: Here are the results with GlassFish:
right click on your project and choose properties. click on Deployement Assembly. click add click on "Java Build Path Entries" select Maven Dependencies" click Finish.
It may be useful for someone, so I'll post it here. I was missing this dependency on my pom.xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency>
I solved by following these steps: Right click in the project > Configure > Convert to Maven project After the conversion, right click in the project > Maven > Update project This fixes the "Deployment Assembly" settings of the project.
Move the jar files from your classpath to web-inf/lib, and run a new tomcat server.
I found a simple solution, Simply add your jars inside WEB-INF-->lib folder..
I had this same issue in WebSphere, but couldn't find a solution even though I verified the Spring dependencies were there and it ran in tomcat just fine. I ended up uninstalling the application and was still getting the error so I think WebSphere was hanging onto some corrupt instance. To fix the issue I had to reinstall the application, stop it, uninstall it and then reinstall it.
For me it was a mistake in the pom.xml - I'd set <scope>provided<scope> on my dependencies, and this was making them not get copied during the mvn package stage. My symptoms were the error message the OP posted, and that the jars were not included in the WEB-INF/lib path inside the .war after package was run. When I removed the scope, the jars appeared in the output, and all loads up fine now.