I try to deploy a simple Jersey application to my Tomcat-Server. But the Endpoint is not responding (404).
When I start this application as a Spring Boot application, everything works. But as a Servlet in Tomcat, the TestEndpoint is not working.
Servlet:
@SpringBootApplication
public class ServletInitializer extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(ServletInitializer.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ServletInitializer.class);
}
}
I have 3 files: JerseyConfig:
@Configuration
public class JerseyConfig extends ResourceConfig {
public JerseyConfig() {
packages("com.example");
register(TestEndpoint.class);
}
}
TestEndpoint:
@Component
@Path("/test")
public class TestEndpoint {
private final Logger log = LoggerFactory.getLogger(this.getClass());
@GET
@Path("/test")
@Produces("application/json")
public Response test () {
log.error("test");
return Response.ok("test").build();
}
}
pom.xml:
http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
<relativePath/>
</parent>
<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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Request: As application: curl http://localhost:8080/test/test (works) As servlet (api.war): http://localhost:8080/api/test/test (does not work) Any ideas?