[英]war in tomcat with apache cxf jax-rs not working
我有一個無法從tomcat容器中運行的rest服務。以下是我的pom.xml和類。我非常感謝您的幫助。
http://maven.apache.org/xsd/maven-4.0.0.xsd“> 4.0.0
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<artifactId>testcxf</artifactId>
<packaging>war</packaging>
測試文件
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxrs</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
彈簧靴類:
@SpringBootApplication
public class TestcxfApplication extends SpringBootServletInitializer{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(TestcxfApplication.class, args);
}
}
服務器類:
@Configuration
public class webs {
@Autowired
private Bus bus;
@Bean
public Server cxfRestServer(Hello hello) {
JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
factory.setBus(bus);
factory.setProvider(new JacksonJsonProvider());
factory.setServiceBean(hello);
factory.setAddress("/rest");
return factory.create();
}
}
和你好類。
日志是這樣的:
在PID為34204的Marius上啟動TestcxfApplication v1.5.10.RELEASE(由C:\\ Program Files \\ Apache Software Foundation \\ Tomcat 8.5中的MARIUS $開始)沒有設置活動的配置文件,恢復為默認的配置文件:default刷新org.springframework.boot。 context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4c65df69:啟動日期[2018年2月12日星期一EET]; 上下文層次結構的根根WebApplicationContext:初始化在288毫秒內完成映射過濾器:'errorPageFilter'到:[/ *]在0.879秒內啟動TestcxfApplication(JVM運行4.531)
它說開始了,但是我無法訪問資源。找不到404資源。
這不需要:
@Configuration
public class webs {
@Autowired
private Bus bus;
@Bean
public Server cxfRestServer(Hello hello) {
JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
factory.setBus(bus);
factory.setProvider(new JacksonJsonProvider());
factory.setServiceBean(hello);
factory.setAddress("/rest");
return factory.create();
}
}
讓CXF Spring Boot啟動程序來處理它。 也嘗試添加:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description</artifactId>
<version>${cxf.version}</version>
</dependency>
以及application.yml
此配置:
# Spring MVC dispatcher servlet path needs to be different than CXF's
server.servlet-path: /
# http://cxf.apache.org/docs/springboot.html#SpringBoot-SpringBootCXFJAX-RSStarter
cxf:
path: /api # CXFServlet URL pattern
jaxrs:
component-scan: true
我在博客中使用Spring Boot,CXF和Swagger實現API時詳細介紹了此配置/設置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.