我正在尝试用球衣配置 spring 靴,但似乎球衣注释不适用于 spring 靴 . 能帮帮我吗
我在服务类中尝试过@RestController而不是@Component和@RequestMapping而不是@Path .
pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.hotel</groupId>
<artifactId>reservations</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>reservations</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath/>
<!-- lookup parent from repository -->
</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-actuator</artifactId>
<version>1.4.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</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>
</project>
Spring Boot Application Xml
package org.hotel;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ReservationApplication {
public static void main(String []args){
SpringApplication.run(ReservationApplication.class, args);
}
}
service class with jersey annotations
package org.hotel.webservices;
import org.springframework.stereotype.Component;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@Component
@Path("/rooms")
public class AddRoomService {
@GET
public String addRoomService(){
return "success";
}
}
1 回答
关于此的在线好教程:Spring Boot Jersey Example July 14, 2017 by Lokesh Gupta . 这似乎是你缺少的部分 .
Jersey Configuration
1:现在我们有一个JAX-RS资源,我们希望从包含Jersey依赖项的spring boot应用程序访问它 . 让我们将此资源注册为 Jersey 资源 .
查看@Component注释 . 它允许在spring boot自动扫描源文件夹中的java类时注册此类 .
2:
ResourceConfig
提供了简化JAX-RS组件注册的高级功能 . 3:使用SpringBootServletInitializer
扩展spring启动应用程序 .