为什么我的JAXRS API将应用程序名称作为应用程序路径?
我创建了一个带有休息和野生蝇的简单版本API,一切都应该有效,但是应用程序路径的名称是我的项目的名称:
我的版本API从我的
pom.xml
: URI应为http:// localhost:8080/version
但是要进行访问,这是http:// localhost:8080/projectName/version
。要加入打开API文件:URI应为
http:// localhost:8080/OpenAPI
但这是http:// localhost:8080/projectName/openapi
我尝试扩展应用程序以设置@applicationpath(“/“/”)
>允许我在应用程序路径上添加元素
示例:http:// localhost:8080/projectName/test/...
。
如何将应用程序路径设置为root(/
)并删除projectName
?
JaxRSActivator class:
@ApplicationPath("/")
public class JaxRSActivator extends Application {
public JaxRSActivator()
{
super();
}
}
VersionFacade class:
@Path("/version")
@Tags
public interface VersionFacade {
@GET
@Produces(TEXT_PLAIN)
@Operation(summary = "Application version",
responses = {
@ApiResponse(responseCode = "200",
description = "Version number",
content = @Content(mediaType = TEXT_PLAIN, schema = @Schema(implementation = String.class)))})
String getVersion();
}
web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" 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">
<!-- public API -->
<security-constraint>
<web-resource-collection>
<web-resource-name>public</web-resource-name>
<url-pattern>/openapi.json</url-pattern>
<url-pattern>/version</url-pattern>
</web-resource-collection>
</security-constraint>
<context-param>
<param-name>resteasy.role.based.security</param-name>
<param-value>true</param-value>
</context-param>
</web-app>
openapi-configuration.yaml file
openapi: 3.0.0
prettyPrint: true
cacheTTL: 0
openAPI:
info:
version: '0.0.1'
title: API config file
I created a simple version API with rest-easy and wildfly, everything should works but the application path has the name of my project:
My version API return the version number from my
pom.xml
: The URI should behttp://localhost:8080/version
but to acces it this ishttp://localhost:8080/projectName/version
.To acces to the open api file : The URI should be
http://localhost:8080/openapi
but this ishttp://localhost:8080/projectName/openapi
I tried to extend Application to set the @ApplicationPath("/")
but it's not working, it just allowed me to add element on the application path
example: http://localhost:8080/projectName/test/...
.
How can I set the application path to the root (/
) and remove the projectName
?
JaxRSActivator class:
@ApplicationPath("/")
public class JaxRSActivator extends Application {
public JaxRSActivator()
{
super();
}
}
VersionFacade class:
@Path("/version")
@Tags
public interface VersionFacade {
@GET
@Produces(TEXT_PLAIN)
@Operation(summary = "Application version",
responses = {
@ApiResponse(responseCode = "200",
description = "Version number",
content = @Content(mediaType = TEXT_PLAIN, schema = @Schema(implementation = String.class)))})
String getVersion();
}
web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" 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">
<!-- public API -->
<security-constraint>
<web-resource-collection>
<web-resource-name>public</web-resource-name>
<url-pattern>/openapi.json</url-pattern>
<url-pattern>/version</url-pattern>
</web-resource-collection>
</security-constraint>
<context-param>
<param-name>resteasy.role.based.security</param-name>
<param-value>true</param-value>
</context-param>
</web-app>
openapi-configuration.yaml file
openapi: 3.0.0
prettyPrint: true
cacheTTL: 0
openAPI:
info:
version: '0.0.1'
title: API config file
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JBoss Wildfly使用Web模块名称(ProjectName.war)作为默认上下文root。要设置它,您需要:
Web-Inf/jboss-web.xml
在您的Web模块中的文件:(如果您不在EAR文件中包装应用程序)
meta-inf/application.xml
文件:(如果将应用程序包装在ear文件中),
如果您使用Eclipse,请小心,有时不会发布您的
application.xml
,因此您需要手动将其放入Wildfly独立/部署中
文件夹。Jboss wildfly use the Web module name (projectName.war) as default context root. To set it you need to:
WEB-INF/jboss-web.xml
file in your Web module:(if you don't package your app in an EAR file)
META-INF/application.xml
file in your EAR:(if you package your app in an EAR file)
If you use Eclipse, careful it sometimes don't publish your
application.xml
so you need to put it manually in your Wildflystandalone/deployments
folder.