我是使用 Fabric8-1.2.0.Beta4 并尝试将 REST 示例应用程序(取自http://tomee.apache.org/examples-trunk/rest-example/README.html)部署到 Fabric8 上的 Tomee 的新手。包括 openejb-cxf-rs 和 tomee-jaxrs 似乎没有帮助。
仅进行了更改: 1) web.xml 按照http://tomee-openejb.979440.n4.nabble.com/Problem-deploying-REST-Examples-on-Eclipse-td4582815.html的建议添加了以下内容:
<servlet>
<servlet-name>ApplicationConfig</servlet-name>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>ApplicationConfig</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>ApplicationConfig</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
2) 在 pom.xml 中添加了 fabric8-maven-plugin 和 distributionManagement 以使用 fabric8:deploy 来部署 war 文件并创建 rest-example 配置文件。
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
<version>1.2.0.Beta4</version>
<configuration>
<parentProfiles>containers-tomee hawtio</parentProfiles>
<profile>${fabric8.profile}</profile>
<profileVersion>${fabric8.version}</profileVersion>
<jolokiaUrl>http://${deploy-host}:${deploy-port}/jolokia</jolokiaUrl>
<webContextPath>/rest-example</webContextPath>
</configuration>
</plugin>
<distributionManagement>
<repository>
<id>fabric-maven-proxy</id>
<name>FMC Maven Proxy</name>
<!-- Change to your target host -->
<url>fabric::default::http://admin:${password}@${deploy-host}:${deploy-port}/maven/upload/</url>
</repository>
</distributionManagement>
之后我创建了一个容器来启动 REST 应用程序。能够看到 index.html,但在尝试调用 WS 时总是出现 403 或 404 错误。
请帮忙。谢谢
已删除 web.xml 中的更改,下载 apache-tomee-jaxrs-1.7.1 并将其配置为在此版本的 tomee 上运行,它能够毫无问题地运行。
需要弄清楚 jaxrs 和 webprofile 版本之间有什么区别,以便使其在 Fabric8-1.2.0.Beta4 上工作
更改后的 Web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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_2_5.xsd"
metadata-complete="false"
version="2.5">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/beans.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
更改后的 beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd">
<!-- do not use import statements if CXFServlet init parameters link to this beans.xml -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxrs:server id="restExampleService" address="/rest-example">
<jaxrs:serviceBeans>
<ref bean="postWS" />
<ref bean="commentWS" />
<ref bean="userWS" />
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="postWS" class="org.superbiz.rest.service.PostService" />
<bean id="commentWS" class="org.superbiz.rest.service.CommentService" />
<bean id="userWS" class="org.superbiz.rest.service.UserService" />
</beans>
还在 Fabric8 中为我的个人资料添加了 4 个功能:spring-web spring cxf-jaxrs fabric-rest