我使用以下工具编写了动态Web应用程序:
这些是此图片中显示的lib文件夹中的jar:
REST资源
@Path("/audit")
public class AuditResource {
private AuditLogService auditLogService = new AuditLogServiceImpl();
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/all")
public List<AuditLog> getAllLog() {
List<AuditLog> allLog = null;
try {
allLog = auditLogService.getAllLog();
} catch(final ApplicationException ex) {
throw ex;
}
if(allLog != null && allLog.isEmpty()) {
throw new ApplicationException("Data not found", Status.NOT_FOUND);
}
return allLog;
}
}
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<welcome-file-list>
<welcome-file>pages/index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey REST Service</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>my.resources</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 REST Service</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
AngularJS控制器
app.controller('main', ['$scope', '$http', function($scope, $http) {
$scope.allLog = function() {
$http.get("services/audit/all")
.then(function successCallback(response) {
$scope.logs = response.data;
}, function errorCallback(response) {
console.log(response);
});
};
$scope.allLog();
}]);
执行此AngularJS控制器和jQuery AJAX调用肯定可以在localhost上运行,没有任何问题,但是当部署在已经运行的远程Weblogic服务器上时它不起作用。有人遇到过同样的问题吗?能够解决这个谜语吗?
当我在远程weblogic服务器上运行应用程序后,在控制台上打印消息
http://hostIP:7011/AuditLogView/services/audit/all
Object {data: "Not Found", status: 404, config: Object, statusText: "Not Found"}
另一个问题是log4j无法在远程服务器上写日志。
此图像中显示的log4j配置和库:
当应用程序在日志中的localhost上部署时,它会在eclipse控制台中显示警告,尽管在lib目录中 jersey-bundle-1.19.1.jar 已经存在。如果它没有在localhost上产生问题那么,我就不那么担心了。
WARNING:
**********
The application is using ServletContainerInitializer class com.sun.jersey.server.impl.container.servlet.JerseyServletContainerInitializer that is loaded from:file:/C:/Oracle/Middleware/Oracle_Home/oracle_common/modules/jersey-servlet-1.18.jar. This initializer overrides the one available in the system.
**********
答案 0 :(得分:2)
Oracle Weblogic将使用自己的嵌套jar覆盖嵌套jar,可能使用了错误的版本。看起来这就是球衣发生的事情。您可以使用类似于以下内容的名为/WEB-INF/weblogic.xml
的weblogic部署描述符:
<weblogic-web-app
xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"
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_2_5.xsd
http://xmlns.oracle.com/weblogic/weblogic-web-app
http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<container-descriptor>
<prefer-application-packages>
<package-name><!-- put jersey package here, e.g. org.glassfish.jersey.* --></package-name>
</prefer-application-packages>
<prefer-application-resources>
<resource-name><!-- put jersey package here, e.g. org.glassfish.jersey.* --></resource-name>
</prefer-application-resources>
</container-descriptor>
<context-root><!-- your app context --></context-root>
</weblogic-web-app>
您可能需要添加多个<package-name>
和<resource-name>
元素才能正确加载所有jar。这是使用weblogic的痛苦之一。
它可能与log4j类似,jar和你的log4j.properties