如何在 tomcat 服务器上部署 Spring boot Web 应用程序
我已经创建了弹簧引导Web应用程序,但是我无法在tomcat上部署弹簧启动Web应用程序WAR文件,并且我能够将其作为java应用程序运行。如何在tomcat上运行spring boot应用程序作为Web服务。我正在使用以下代码。如果可以在tomcat上运行,请帮助我使用注释而不使用web.xml并使用web.xml。
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
其余控制器的以下代码
@RestController
public class HelloWorld{
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public ResponseEntity<String> get() {
return new ResponseEntity<String>("Hello World", HttpStatus.OK);
}
}
关注Pom.xml我正在使用
<groupId>org.springframework</groupId>
<artifactId>web-service</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.0.RELEASE</version>
</parent>
<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>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.6</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
<packaging>war</packaging>