学習のため(Spring Bootは魅力的です)、Jerseyを使用してWebアプリケーションをセットアップしようとしていますとスプリング(DIの場合)。私はそれを動作させるために管理してきましたが、Spring XML設定のみで動作します。私はResourceConfigの@ web.xmlコンフィグレーションで@ConfigurationからJersey 2/Spring 4ロードBeanを作成する方法
@ApplicationPath("/api")
public class JerseyWebApp extends ResourceConfig {
public JerseyWebApp() {
packages("com.company.controller");
}
}
マイHelloController.java
@Path("/hello")
public class HelloController {
private HelloService helloService;
@Autowired
public HelloController(HelloService helloService) {
this.helloService = helloService;
}
@GET
public String hello() {
return helloService.sayHello();
}
}
私HelloService.java
@Component
@Scope(value = BeanDefinition.SCOPE_PROTOTYPE)
public class HelloService {
public String sayHello() {
return "hello from jersey webapp";
}
}
と私の春のapplicationContext.xmlをを高めてい
また<properties>
<jersey2.version>2.23.2</jersey2.version>
<jaxrs.version>2.0.1</jaxrs.version>
<spring.version>4.3.2.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>${jersey2.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring3</artifactId>
<version>${jersey2.version}</version>
<exclusions>
<exclusion>
<artifactId>spring-context</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-beans</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-core</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-web</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>jersey-server</artifactId>
<groupId>org.glassfish.jersey.core</groupId>
</exclusion>
<exclusion>
<artifactId>
jersey-container-servlet-core
</artifactId>
<groupId>org.glassfish.jersey.containers</groupId>
</exclusion>
<exclusion>
<artifactId>hk2</artifactId>
<groupId>org.glassfish.hk2</groupId>
</exclusion>
</exclusions>
</dependency>
<!--Spring 4-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies>
私のポンポンファイルを添付210
ジャージーを@Configurationクラスを経由して豆をロードするために取得することが可能ですか私は、全体のアプリケーションをブートストラップするために春のWeb/MVCを使用して考慮しなければなりません。
周りの非常に素晴らしい作品:ここでは鉱山があります:https://github.com/bric3/jersey2-spring4-example – Brice