JERSEY and JAX-RS

I am trying to deploy the simplest REST service using jersey and JAX-RS, but I get this error,

HTTP ERROR: 404 NOT FOUND RequestURI = / hosting / demo / example Powered by Jetty: //

Where I think I did everything right, below is the code that I use for it.

POM.XML (only insert knitted part)

<dependency> <!-- the implementation of JAX-RS --> <groupId>com.sun.jersey</groupId> <artifactId>jersey-server</artifactId> <version>1.0.1</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-core</artifactId> <version>1.0.1</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-client</artifactId> <version>1.0.1</version> <scope>compile</scope> </dependency> 

web.xml

 <servlet> <servlet-name>jersey</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>mop.core.service.restservices</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>jersey</servlet-name> <url-pattern>/demo</url-pattern> </servlet-mapping> 

My class with @GET

 package mop.core.service.restservices; import javax.swing.JOptionPane; import javax.ws.rs.Consumes; import javax.ws.rs.FormParam; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; @Path("/example") public class PricePointRestService { @GET @Produces("text/plain") public String getPricePoint(){ JOptionPane.showMessageDialog(null, "GET CALLED"); return "hello"; } @POST @Produces("application/xml") @Consumes({"application/x-www-form-urlencoded", "multipart/form-data"}) public String doPost(@FormParam("xml") String xml) { return "<xml></xml>"; } } 

I find the URL: http: // localhost / hosting / demo / example

+4
source share
4 answers

Change your url template in your web.xml to:

 <url-pattern>/demo/*</url-pattern> 
+3
source

Are you sure the β€œhosting” part of the URL is correct? What is web application deployment? Can you click on any pages in a web application?

Try adding jsp to your web application and see if you can do it.

0
source

Agree with Damo on:

 <url-pattern>/demo/*</url-pattern> 

Also add:

 <load-on-startup>1</load-on-startup> 

front:

 </servlet> 

I assume you are using Maven. Hibernate 3.2.4 works fine in ASM 3.1, so you can ignore this dependency. This post will work with Jersey.

  <dependency><!-- hibernate 3.2.4.ga --> <groupId>org.hibernate</groupId> <artifactId>hibernate</artifactId> <version>3.2.6.ga</version> <exclusions> <exclusion> <groupId>asm</groupId> <artifactId>asm</artifactId> </exclusion> <exclusion> <groupId>asm</groupId> <artifactId>asm-attrs</artifactId> </exclusion> <exclusion> <groupId>cglib</groupId> <artifactId>cglib</artifactId> </exclusion> </exclusions> </dependency> 
0
source

The problem I found out was the ASM 2.2.3 and Jersey compatibility problem, which requires ASM 3.1. Sleep mode depends on ASm 2.2.3.

This error is reported at http://opensource.atlassian.com/projects/hibernate/browse/EJB-358?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

I am trying to find work for this, but they do not seem to work, since cglib 2.2 and cglib-nodep do not help either.

javassist cannot be used through the hibernate XML configuration file, this requires the hibernate.properties file, where the project I'm working on is using hibernate.cfg.xml.

Any solution?

0
source

Source: https://habr.com/ru/post/1285946/


All Articles