当我在tomcat服务器上部署它时,我的应用程序工作正常,但如果部署在weblogic上则无法正常工作。
Tomcat verison是:7.0.47
Weblogic版本是:12.2.1.2.0
有一个简单的休息端点返回一个JSON:
http://localhost:8080/MyApplication/rest/configuration/test
在tomcat上运行正常,在weblogic上我只得到字符串" Not Found"。
在日志文件中,我发现的唯一警告如下:
<Warning> <JAXRSIntegration> <MyApplication> <[ACTIVE] ExecuteThread: '12' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <24ad6e0e-7bbc-4781-b294-f546069677ec-00000007> <1511013418859> <[severity-value: 16] [rid: 0] [partition-id: 0] [partition-name: DOMAIN] > <BEA-2192510> <Cannot add Jersey servlet for application class org.glassfish.jersey.server.ResourceConfig because ApplicationPath annotation is not set on it.>
<Warning> <JAXRSIntegration> <MyApplication> <[ACTIVE] ExecuteThread: '12' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <24ad6e0e-7bbc-4781-b294-f546069677ec-00000007> <1511013418860> <[severity-value: 16] [rid: 0] [partition-id: 0] [partition-name: DOMAIN] > <BEA-2192510> <Cannot add Jersey servlet for application class org.glassfish.jersey.server.ResourceConfig$WrappingResourceConfig because ApplicationPath annotation is not set on it.>
<Warning> <JAXRSIntegration> <MyApplication> <[ACTIVE] ExecuteThread: '12' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <24ad6e0e-7bbc-4781-b294-f546069677ec-00000007> <1511013418861> <[severity-value: 16] [rid: 0] [partition-id: 0] [partition-name: DOMAIN] > <BEA-2192510> <Cannot add Jersey servlet for application class org.glassfish.jersey.server.ResourceConfig$RuntimeConfig because ApplicationPath annotation is not set on it.>
终点:
@Path("/configuration")
@NoCache
public class ConfigurationResource {
@GET
@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
public Response getClientConfig() {
Map<String, Object> map = new HashMap<>();
map.put("test", "Test is running.");
return Response.ok(map).build();
}
...
}
public class MyApplication extends ResourceConfig {
public MyApplication() {
register(ConfigurationResource.class);
}
}
来自web.xml的
<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.sample.rest.MyApplication</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</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>
weblogic.xml中:
<weblogic-web-app>
<container-descriptor>
<prefer-application-packages>
<package-name>javax.ws.rs</package-name>
<package-name>javax.persistence</package-name>
<package-name>org.apache.commons</package-name>
<package-name>org.slf4j</package-name>
<package-name>org.apache.commons.logging</package-name>
</prefer-application-packages>
</container-descriptor>
</weblogic-web-app>
我已经尝试添加注释但没有效果 有没有人知道我能做些什么让它发挥作用?
答案 0 :(得分:1)
我找到了解决这个问题的方法 从weblogic.xml中删除一些行后,它起作用了:
weblogic.xml中:
<weblogic-web-app>enter code here
<container-descriptor>
<prefer-application-packages>
<package-name>org.apache.commons</package-name>
<package-name>org.slf4j</package-name>
<package-name>org.apache.commons.logging</package-name>
</prefer-application-packages>
</container-descriptor>
</weblogic-web-app>
所以我要删除:
<package-name>javax.ws.rs</package-name>
<package-name>javax.persistence</package-name>
这是唯一的事情。 不幸的是,没有真正提示实际问题是什么,因为我在任何日志文件中都没有发现错误/警告条目。
似乎这些软件包与weblogic软件包提供的软件包不兼容。 我认为还应该检查pom文件中的相关依赖性是否在“提供”范围内。