我想在Glassfish 4.1中运行Wildfly 9.0.0中的应用程序。这个应用程序是使用JAX-RS 2的Rest Api。当我尝试在Wildfly中部署时,错误是:
[standalone@127.0.0.1:9990 /]部署 /home/andres/Documentos/SistemaInventarios/libreria/dist/libreria.war {“WFLYCTL0062:复合操作失败并被回滚。步骤 失败:“=> {”操作步骤-2“=> {”WFLYCTL0080:失败 服务“=> { “jboss.undertow.deployment.default-server.default-host./libreria.UndertowDeploymentInfoService” => “服务jboss.undertow.deployment.default-server.default-host./libreria.UndertowDeploymentInfoService中的org.jboss.msc.service.StartException: 无法启动服务 引起:java.lang.IllegalArgumentException:UT010011:类com.libreria.util.CorsFilter类型的过滤器cors未实现 javax.servlet.Filter的“}}}}
所以,在之前的步骤中,我通过WildFly Cli添加了Posgresql jar,如下所示:
模块add --name = org.postgres --resources = /家庭/安德烈/ Escritorio / pruebacono / archivoutiles / PostgreSQL相关9.3-1102.jdbc4.jar --dependencies = javax.api,javax.transaction.api
将驱动程序添加到数据库
/子系统=数据源/ JDBC驱动器= postgres的:添加(驱动程序名称= “postgres的”,驱动器模块名= “org.postgres”,驱动器类名= org.postgresql.Driver)
创建使用Jdbc驱动程序安装的数据源
data-source add --jndi-name = java:jboss / LibraryPostgresDS --name = PostgresPool --connection-url = jdbc:postgresql:// localhost:5432 / library --driver-name = postgres --user-name = postgres --password = andres
测试连接成功进行JDBC连接。
我的web.xml是:
var url;
$("script").each(function () {
if ($(this).attr("src").indexOf("[YOUR_SCRIPT_NAME.JS]") > 0) {
url = $(this).attr("src");
url = url.substr(0, url.lastIndexOf("/"));
return false;
}
});
var final_url = url + "/your_target_script.js"
我的角色过滤器是:
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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">
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<servlet>
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.libreria.andres;com.libreria.service;com.libreria.util</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
<param-value>com.libreria.util.CorsFilter</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>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ServletAdaptor</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
<param-value>true</param-value>
</context-param>
<filter>
<filter-name>cors</filter-name>
<filter-class>com.libreria.util.CorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>cors</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
我的persistence.xml生成了Netbeans 8.0.2 IDE:
package com.libreria.util;
import java.io.IOException;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.container.PreMatching;
import javax.ws.rs.ext.Provider;
@PreMatching
@Provider
public class CorsFilter implements ContainerResponseFilter {
@Override
public void filter(ContainerRequestContext request,
ContainerResponseContext response) throws IOException {
response.getHeaders().add("Access-Control-Allow-Origin", "*");
response.getHeaders().add("Access-Control-Allow-Headers",
"origin, content-type, accept, authorization");
response.getHeaders().add("Access-Control-Allow-Headers",
"origin, content-type, accept, authorization");
String crunchifyRequestHeader = request.getHeaderString("Access-Control-Request-Headers");
if (null != crunchifyRequestHeader && !crunchifyRequestHeader.equals(null)) {
response.getHeaders().add("Access-Control-Allow-Headers", crunchifyRequestHeader);
}
response.getHeaders().add("Access-Control-Allow-Credentials", "true");
response.getHeaders().add("Access-Control-Allow-Methods",
"GET, POST, PUT, DELETE, OPTIONS, HEAD");
}
}
我的standalone.xml如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="libreriaPU" transaction-type="JTA">
<jta-data-source>java:jboss/LibraryPostgresDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>