繁体   English   中英

与apache cxf jax-rs在tomcat中发生战争

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM