简体   繁体   中英

How to avoid application name in URL - RESTEasy Java 8

I am very new to RESTEasy and the Java EE stack. I used to use the Spring framework and its modules instead. Today I thought to get familiar with Java EE's RESTEasy and dig through a list of problems so far, but finally my app started and I have also figured out that I need to type the url like this:

http://localhost:8080/com.maciej/message/asdasda

instead of:

http://localhost:8080/message/asdasda

as I did in spring rest

I wonder why is that? What should I configure to avoid typing com.maciej to the url?

Here are my config files, if you need more please let me know in comments and I will paste them.

web.xml

<?xml version="1.0"?>
<!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>
    <display-name>RestEasy sample Web Application</display-name>

    <listener>
        <listener-class>
            org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
        </listener-class>
    </listener>

    <servlet>
        <servlet-name>Resteasy</servlet-name>
        <servlet-class>
            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
        </servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>com.maciej.MessageApplication</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>Resteasy</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

</web-app>

Application class:

import javax.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;

public class MessageApplication extends Application {
    private Set<Object> singletons = new HashSet<Object>();

    public MessageApplication() {
        singletons.add(new MainRest());
    }

    @Override
    public Set<Object> getSingletons() {
        return singletons;
    }
}

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.maciej</groupId>
  <artifactId>com.maciej</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>com.maciej Maven Webapp</name>
  <url>http://maven.apache.org</url>

    <repositories>
        <repository>
            <id>JBoss repository</id>
            <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
            <version>2.2.1.GA</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>com.maciej</finalName>
    </build>
</project>

I use JBoss 9.0.0.Beta as my application server. Thanks!

您可以在应用程序类中添加@ApplicationPath(“ /”),这应该可以工作

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM