diff --git a/spring-boot-autoconfigure/pom.xml b/spring-boot-autoconfigure/pom.xml index 10ee77127a4..d880067a3d3 100644 --- a/spring-boot-autoconfigure/pom.xml +++ b/spring-boot-autoconfigure/pom.xml @@ -60,6 +60,26 @@ flyway-core true + + org.glassfish.jersey.core + jersey-server + true + + + org.glassfish.jersey.containers + jersey-container-servlet-core + true + + + org.glassfish.jersey.containers + jersey-container-servlet + true + + + org.glassfish.jersey.ext + jersey-spring3 + true + commons-dbcp commons-dbcp diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java new file mode 100644 index 00000000000..352fe7796db --- /dev/null +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java @@ -0,0 +1,106 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.jersey; + +import javax.annotation.PostConstruct; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRegistration; +import javax.ws.rs.ApplicationPath; + +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.server.spring.SpringComponentProvider; +import org.glassfish.jersey.servlet.ServletContainer; +import org.glassfish.jersey.servlet.ServletProperties; +import org.springframework.beans.factory.ListableBeanFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; +import org.springframework.boot.context.embedded.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.core.annotation.Order; +import org.springframework.web.WebApplicationInitializer; +import org.springframework.web.filter.RequestContextFilter; + +/** + * @author Dave Syer + * + */ +@Configuration +@ConditionalOnClass({ SpringComponentProvider.class, ServletRegistration.class }) +@ConditionalOnBean(ResourceConfig.class) +@ConditionalOnWebApplication +@Order(Ordered.HIGHEST_PRECEDENCE) +@AutoConfigureBefore(DispatcherServletAutoConfiguration.class) +public class JerseyAutoConfiguration implements WebApplicationInitializer { + + @Autowired + private ListableBeanFactory context; + + @Autowired + private ResourceConfig config; + + private String path; + + @PostConstruct + public void path() { + path = findPath(AnnotationUtils.findAnnotation(config.getClass(), + ApplicationPath.class)); + } + + @Bean + @ConditionalOnMissingBean + public RequestContextFilter requestContextFilter() { + return new RequestContextFilter(); + } + + @Bean + @ConditionalOnMissingBean(name = "jerseyServletRegistration") + public ServletRegistrationBean jerseyServletRegistration() { + Class configType = config.getClass(); + ServletRegistrationBean registration = new ServletRegistrationBean( + new ServletContainer(), path); + registration.addInitParameter(ServletProperties.JAXRS_APPLICATION_CLASS, + configType.getName()); + registration.setName("jerseyServlet"); + return registration; + } + + @Override + public void onStartup(ServletContext servletContext) throws ServletException { + // We need to switch *off* the Jersey WebApplicationInitializer because it + // will try and register a ContextLoaderListener which we don't need + servletContext.setInitParameter("contextConfigLocation", ""); + } + + private static String findPath(ApplicationPath annotation) { + // Jersey doesn't like to be the default servlet, so map to /* as a fallback + if (annotation == null) { + return "/*"; + } + String path = annotation.value(); + return path.isEmpty() || path.equals("/") ? "/*" : path + "/*"; + } + +} diff --git a/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories index a997d9f8b78..da5ccd55843 100644 --- a/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories @@ -34,6 +34,7 @@ org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchAutoConfigurat org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchDataAutoConfiguration,\ org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,\ org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration,\ +org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration,\ org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\ org.springframework.boot.autoconfigure.mobile.DeviceResolverAutoConfiguration,\ org.springframework.boot.autoconfigure.mobile.DeviceDelegatingViewResolverAutoConfiguration,\ diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/CustomServletPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/CustomServletPathTests.java new file mode 100644 index 00000000000..fc89d520c62 --- /dev/null +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/CustomServletPathTests.java @@ -0,0 +1,99 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.jersey; + +import static org.junit.Assert.assertEquals; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.glassfish.jersey.server.ResourceConfig; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.jersey.CustomServletPathTests.Application; +import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; +import org.springframework.boot.test.IntegrationTest; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.TestRestTemplate; +import org.springframework.context.annotation.Import; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.web.client.RestTemplate; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = Application.class) +@IntegrationTest("server.port=0") +@WebAppConfiguration +public class CustomServletPathTests { + + @Value("${local.server.port}") + private int port; + + private RestTemplate restTemplate = new TestRestTemplate(); + + @Test + public void contextLoads() { + ResponseEntity entity = restTemplate.getForEntity("http://localhost:" + port + "/rest/hello", String.class); + assertEquals(HttpStatus.OK, entity.getStatusCode()); + } + + @MinimalWebConfiguration + @ApplicationPath("/rest") + @Path("/hello") + public static class Application extends ResourceConfig { + + @Value("${message:World}") + private String msg; + + @GET + public String message() { + return "Hello " + msg; + } + + public Application() { + register(Application.class); + } + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + + } + + @Target(ElementType.TYPE) + @Retention(RetentionPolicy.RUNTIME) + @Documented + @Import({ EmbeddedServletContainerAutoConfiguration.class, + ServerPropertiesAutoConfiguration.class, JerseyAutoConfiguration.class, + PropertyPlaceholderAutoConfiguration.class }) + protected static @interface MinimalWebConfiguration { + } + +} diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/DefaultServletPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/DefaultServletPathTests.java new file mode 100644 index 00000000000..bcabf6f6ba7 --- /dev/null +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/DefaultServletPathTests.java @@ -0,0 +1,98 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.jersey; + +import static org.junit.Assert.assertEquals; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.glassfish.jersey.server.ResourceConfig; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.jersey.DefaultServletPathTests.Application; +import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; +import org.springframework.boot.test.IntegrationTest; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.TestRestTemplate; +import org.springframework.context.annotation.Import; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.web.client.RestTemplate; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = Application.class) +@IntegrationTest("server.port=0") +@WebAppConfiguration +public class DefaultServletPathTests { + + @Value("${local.server.port}") + private int port; + + private RestTemplate restTemplate = new TestRestTemplate(); + + @Test + public void contextLoads() { + ResponseEntity entity = restTemplate.getForEntity("http://localhost:" + + port + "/hello", String.class); + assertEquals(HttpStatus.OK, entity.getStatusCode()); + } + + @MinimalWebConfiguration + @Path("/hello") + public static class Application extends ResourceConfig { + + @Value("${message:World}") + private String msg; + + public Application() { + register(Application.class); + } + + @GET + public String message() { + return "Hello " + msg; + } + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + + } + + @Target(ElementType.TYPE) + @Retention(RetentionPolicy.RUNTIME) + @Documented + @Import({ EmbeddedServletContainerAutoConfiguration.class, + ServerPropertiesAutoConfiguration.class, JerseyAutoConfiguration.class, + PropertyPlaceholderAutoConfiguration.class }) + protected static @interface MinimalWebConfiguration { + } + +} diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index dd0ebcdcae9..d5e8b676a28 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -85,6 +85,7 @@ 2.2.0.v201112011158 1.1.6 2.0.5 + 2.7 2.4 1.2.2 0.9.1 @@ -261,6 +262,11 @@ spring-boot-starter-jdbc 1.2.0.BUILD-SNAPSHOT + + org.springframework.boot + spring-boot-starter-jersey + 1.2.0.BUILD-SNAPSHOT + org.springframework.boot spring-boot-starter-jetty @@ -856,6 +862,26 @@ flyway-core ${flyway.version} + + org.glassfish.jersey.core + jersey-server + ${jersey.version} + + + org.glassfish.jersey.containers + jersey-container-servlet-core + ${jersey.version} + + + org.glassfish.jersey.containers + jersey-container-servlet + ${jersey.version} + + + org.glassfish.jersey.ext + jersey-spring3 + ${jersey.version} + org.hamcrest hamcrest-core diff --git a/spring-boot-samples/pom.xml b/spring-boot-samples/pom.xml index 3df42422192..ac005c1d095 100644 --- a/spring-boot-samples/pom.xml +++ b/spring-boot-samples/pom.xml @@ -37,6 +37,8 @@ spring-boot-sample-flyway spring-boot-sample-hornetq spring-boot-sample-integration + spring-boot-sample-jersey + spring-boot-sample-jersey1 spring-boot-sample-jetty spring-boot-sample-jta-atomikos spring-boot-sample-jta-bitronix diff --git a/spring-boot-samples/spring-boot-sample-jersey/pom.xml b/spring-boot-samples/spring-boot-sample-jersey/pom.xml new file mode 100644 index 00000000000..b77538862cf --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jersey/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + spring-boot-sample-jersey + 1.0.0.BUILD-SNAPSHOT + war + + spring-boot-sample-jersey + Spring Boot Jersey sample project + + + + org.springframework.boot + spring-boot-samples + 1.2.0.BUILD-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-jersey + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/Endpoint.java b/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/Endpoint.java new file mode 100644 index 00000000000..8bdc7bdb353 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/Endpoint.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.jersey; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +/** + * @author Dave Syer + * + */ +@Component +@Path("/hello") +public class Endpoint { + + @Value("${message:World}") + private String msg; + + @GET + public String message() { + return "Hello " + msg; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/JerseyConfig.java b/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/JerseyConfig.java new file mode 100644 index 00000000000..f9299d825be --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/JerseyConfig.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.jersey; + +import org.glassfish.jersey.server.ResourceConfig; +import org.springframework.stereotype.Component; + +@Component +public class JerseyConfig extends ResourceConfig { + + public JerseyConfig() { + register(Endpoint.class); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/SampleJerseyApplication.java b/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/SampleJerseyApplication.java new file mode 100644 index 00000000000..982795fde27 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/SampleJerseyApplication.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.jersey; + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.web.SpringBootServletInitializer; +import org.springframework.context.annotation.ComponentScan; + +@ComponentScan +@EnableAutoConfiguration +public class SampleJerseyApplication extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(SampleJerseyApplication.class); + } + + public static void main(String[] args) { + new SampleJerseyApplication().configure(new SpringApplicationBuilder(SampleJerseyApplication.class)).run( + args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java b/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java new file mode 100644 index 00000000000..d09f48f93da --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java @@ -0,0 +1,51 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.jersey; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.IntegrationTest; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.web.client.RestTemplate; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = SampleJerseyApplication.class) +@IntegrationTest("server.port=0") +@WebAppConfiguration +public class SampleJerseyApplicationTests { + + @Value("${local.server.port}") + private int port; + + private RestTemplate restTemplate =new TestRestTemplate(); + + @Test + public void contextLoads() { + ResponseEntity entity = restTemplate.getForEntity("http://localhost:" + + port + "/hello", String.class); + assertEquals(HttpStatus.OK, entity.getStatusCode()); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jersey1/pom.xml b/spring-boot-samples/spring-boot-sample-jersey1/pom.xml new file mode 100644 index 00000000000..feab0180757 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jersey1/pom.xml @@ -0,0 +1,70 @@ + + + 4.0.0 + + spring-boot-sample-jersey1 + 0.0.1-SNAPSHOT + jar + + spring-boot-sample-jersey1 + Spring Boot Sample with Jersey 1.x + + + + org.springframework.boot + spring-boot-samples + 1.2.0.BUILD-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-tomcat + + + org.springframework + spring-web + + + com.sun.jersey + jersey-servlet + 1.13 + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + com.sun.jersey + jersey-servlet + + + com.sun.jersey + jersey-server + + + com.sun.jersey + jersey-core + + + + + + + + diff --git a/spring-boot-samples/spring-boot-sample-jersey1/src/main/java/sample/jersey1/SampleJersey1Application.java b/spring-boot-samples/spring-boot-sample-jersey1/src/main/java/sample/jersey1/SampleJersey1Application.java new file mode 100644 index 00000000000..f8c53017018 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jersey1/src/main/java/sample/jersey1/SampleJersey1Application.java @@ -0,0 +1,47 @@ +package sample.jersey1; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.embedded.FilterRegistrationBean; +import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import com.sun.jersey.spi.container.servlet.ServletContainer; + +@Configuration +@ComponentScan +@EnableAutoConfiguration +@Path("/") +public class SampleJersey1Application { + + public static void main(String[] args) { + new SpringApplicationBuilder(SampleJersey1Application.class).web(true).run(args); + } + + @GET + @Produces("text/plain") + public String hello() { + return "Hello World"; + } + + @Bean + // Not needed if Spring Web MVC is also present on claspath + public TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory() { + return new TomcatEmbeddedServletContainerFactory(); + } + + @Bean + public FilterRegistrationBean jersey() { + FilterRegistrationBean bean = new FilterRegistrationBean(); + bean.setFilter(new ServletContainer()); + bean.addInitParameter("com.sun.jersey.config.property.packages", "com.sun.jersey;demo"); + return bean; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jersey1/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-jersey1/src/main/resources/application.properties new file mode 100644 index 00000000000..e69de29bb2d diff --git a/spring-boot-samples/spring-boot-sample-jersey1/src/test/java/sample/jersey1/SampleJersey1ApplicationTests.java b/spring-boot-samples/spring-boot-sample-jersey1/src/test/java/sample/jersey1/SampleJersey1ApplicationTests.java new file mode 100644 index 00000000000..bcaccc23e35 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jersey1/src/test/java/sample/jersey1/SampleJersey1ApplicationTests.java @@ -0,0 +1,30 @@ +package sample.jersey1; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.IntegrationTest; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.TestRestTemplate; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import sample.jersey1.SampleJersey1Application; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = SampleJersey1Application.class) +@WebAppConfiguration +@IntegrationTest("server.port:0") +public class SampleJersey1ApplicationTests { + + @Value("${local.server.port}") + private int port; + + @Test + public void contextLoads() { + assertEquals("Hello World", new TestRestTemplate().getForObject("http://localhost:" + port + "/", String.class)); + } + +} diff --git a/spring-boot-starters/pom.xml b/spring-boot-starters/pom.xml index bd946e641ca..8d965b2fa8a 100644 --- a/spring-boot-starters/pom.xml +++ b/spring-boot-starters/pom.xml @@ -35,6 +35,7 @@ spring-boot-starter-hornetq spring-boot-starter-integration spring-boot-starter-jdbc + spring-boot-starter-jersey spring-boot-starter-jetty spring-boot-starter-jta-atomikos spring-boot-starter-jta-bitronix diff --git a/spring-boot-starters/spring-boot-starter-jersey/pom.xml b/spring-boot-starters/spring-boot-starter-jersey/pom.xml new file mode 100644 index 00000000000..868490025a5 --- /dev/null +++ b/spring-boot-starters/spring-boot-starter-jersey/pom.xml @@ -0,0 +1,69 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starters + 1.2.0.BUILD-SNAPSHOT + + spring-boot-starter-jersey + spring-boot-starter-jersey + Spring Boot Jersey Starter + http://projects.spring.io/spring-boot/ + + Pivotal Software, Inc. + http://www.spring.io + + + ${basedir}/../.. + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-tomcat + + + com.fasterxml.jackson.core + jackson-databind + + + org.hibernate + hibernate-validator + + + org.springframework + spring-core + + + commons-logging + commons-logging + + + + + org.springframework + spring-web + + + org.glassfish.jersey.core + jersey-server + + + org.glassfish.jersey.containers + jersey-container-servlet-core + + + org.glassfish.jersey.containers + jersey-container-servlet + + + org.glassfish.jersey.ext + jersey-spring3 + + + diff --git a/spring-boot-starters/spring-boot-starter-jersey/src/main/resources/META-INF/spring.provides b/spring-boot-starters/spring-boot-starter-jersey/src/main/resources/META-INF/spring.provides new file mode 100644 index 00000000000..8bdafc67453 --- /dev/null +++ b/spring-boot-starters/spring-boot-starter-jersey/src/main/resources/META-INF/spring.provides @@ -0,0 +1 @@ +provides: jersey-container-servlet-core,jersey-container-servlet,jersey-server \ No newline at end of file