为什么部署后在 RESTEasy (wildfly) 上出现 404 错误?
Why do I get 404 error on RESTEasy (wildfly) after deploy?
我在 Java 中创建了 3 个简单的文件,并使用 mvn clean package wildfly:deploy 命令 运行 它。这一切都已成功部署(至少控制台中是这样写的)。然而,当我去
http://localhost:8080/lab-rest-api/library/book
我收到 404 错误。我的项目位于模块 lab-rest-api 中(它只是项目的一部分,其他模块用于网络消费 - ejb、ear 等)
我做了网络服务和简单的网络消费,效果很好。但是,REST API 不工作。
这是我的 pom.xml:
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.6.3.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.6.3.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>3.6.3.Final</version>
<scope>provided</scope>
</dependency>
我的扩展应用程序:
@ApplicationPath("/")
public class RESTMain extends Application {
public RESTMain() {
System.out.println("whatever");
}
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(ServicesInterface.class);
return classes;
}
}
还有我的服务:
@Path("/library")
@Consumes({"application/json"})
@Produces({"application/json"})
public class ServicesInterface {
Book booky = new Book();
@GET
@Path("/book/{title}")
public Book getBook(@PathParam("title") String title){
return booky;
}
@PUT
@Path("/book/{title}")
public Book addBook(@PathParam("title") String title, @QueryParam("author") String author){
return booky;
}
@POST
@Path("/book/{title}")
public Book updateBook(@PathParam("title") String title, String author){
return booky;
}
@DELETE
@Path("/book/{title}")
public Book removeBook(@PathParam("title") String title){
return booky;
}
}
"Book" 是一个简单的 class,带有 2 个字符串(作者和标题)以及它的 getter 和 setter。
您似乎没有为 \book
实施 Get
。您只实现了 \book\{title}
对于您当前的实施,请尝试 \book\{meaningful title in your database}
好的,
解决此问题的步骤:
1) 包装一个war
将 <packaging>war</packaging>
添加到您的 pom 文件。
还要加上
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
2) 升级wildfly maven插件
<version.wildfly.maven.plugin>2.0.1.Final</version.wildfly.maven.plugin>
3) 删除重复依赖
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
<scope>compile</scope>
</dependency>
4) 从 wildfly-maven-plugin 配置中删除这些额外的东西
<inherited>true</inherited>
<configuration>
<skip>true</skip>
</configuration>
5) 运行 你的 mvn clean package wildfly:deploy
6) 浏览到 http://localhost:8080/lab-rest-api-1.0-SNAPSHOT/library/book/asd
奖励: 的已接受答案显示了如何从 URL.
中删除 -1.0-SNAPSHOT
我在 Java 中创建了 3 个简单的文件,并使用 mvn clean package wildfly:deploy 命令 运行 它。这一切都已成功部署(至少控制台中是这样写的)。然而,当我去
http://localhost:8080/lab-rest-api/library/book
我收到 404 错误。我的项目位于模块 lab-rest-api 中(它只是项目的一部分,其他模块用于网络消费 - ejb、ear 等)
我做了网络服务和简单的网络消费,效果很好。但是,REST API 不工作。
这是我的 pom.xml:
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.6.3.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.6.3.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>3.6.3.Final</version>
<scope>provided</scope>
</dependency>
我的扩展应用程序:
@ApplicationPath("/")
public class RESTMain extends Application {
public RESTMain() {
System.out.println("whatever");
}
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(ServicesInterface.class);
return classes;
}
}
还有我的服务:
@Path("/library")
@Consumes({"application/json"})
@Produces({"application/json"})
public class ServicesInterface {
Book booky = new Book();
@GET
@Path("/book/{title}")
public Book getBook(@PathParam("title") String title){
return booky;
}
@PUT
@Path("/book/{title}")
public Book addBook(@PathParam("title") String title, @QueryParam("author") String author){
return booky;
}
@POST
@Path("/book/{title}")
public Book updateBook(@PathParam("title") String title, String author){
return booky;
}
@DELETE
@Path("/book/{title}")
public Book removeBook(@PathParam("title") String title){
return booky;
}
}
"Book" 是一个简单的 class,带有 2 个字符串(作者和标题)以及它的 getter 和 setter。
您似乎没有为 \book
实施 Get
。您只实现了 \book\{title}
对于您当前的实施,请尝试 \book\{meaningful title in your database}
好的,
解决此问题的步骤:
1) 包装一个war
将 <packaging>war</packaging>
添加到您的 pom 文件。
还要加上
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
2) 升级wildfly maven插件
<version.wildfly.maven.plugin>2.0.1.Final</version.wildfly.maven.plugin>
3) 删除重复依赖
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
<scope>compile</scope>
</dependency>
4) 从 wildfly-maven-plugin 配置中删除这些额外的东西
<inherited>true</inherited>
<configuration>
<skip>true</skip>
</configuration>
5) 运行 你的 mvn clean package wildfly:deploy
6) 浏览到 http://localhost:8080/lab-rest-api-1.0-SNAPSHOT/library/book/asd
奖励: