在tomcat中部署后无法访问Spring Boot应用程序
我已经使用Spring Boot创建了一个RESTAPI。我正在使用gradle作为构建工具。我已经使用嵌入式容器测试了该应用程序,并且运行良好。我可以通过访问我的应用程序localhost:8080/foo/bar
。
现在,我已将其部署到tomcat,没有任何错误。
Mar 17, 2016 1:58:47 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /usr/local/apache-tomcat-7.0.65/webapps/foo.war
Mar 17, 2016 1:58:48 PM org.apache.catalina.startup.TldConfig execute
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Mar 17, 2016 1:58:48 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive /usr/local/apache-tomcat-7.0.65/webapps/foo.war has finished in 623 ms
但是我现在无法通过访问该应用程序localhost:8080/foo/bar
。我可以看到tomcat正在运行localhost:8080
这是build.gradle
文件。
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: 'war'
war {
baseName = 'foo'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
configurations{
providedRuntime
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
compile 'com.google.code.gson:gson:2.6.2'
compile 'org.springframework:spring-webmvc:4.2.5.RELEASE'
compile 'org.json:json:20151123'
providedRuntime 'javax.ws.rs:javax.ws.rs-api:2.0.1'
providedRuntime 'javax.servlet:javax.servlet-api:3.1.0'
providedRuntime 'javax.servlet:jstl:1.2'
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.11'
}
我有一个application.properties
包含以下代码的文件
server.context-path=/foo
并且我在控制器中的请求映射设置为
@CrossOrigin
@RequestMapping("/bar")
public String bar(){
// Code
}
@SpringBootApplication
public class FooApplication {
public static void main(String[] args) {
SpringApplication.run(FooApplication.class, args);
}
// Used when deploying to a standalone servlet container
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(FooApplication.class);
}
}
-
要部署SpringBoot应用程序,您必须具有一个扩展
org.springframework.boot.context.web.SpringBootServletInitializer
和覆盖的配置类。org.springframework.boot.context.web.SpringBootServletInitializer.configure(SpringApplicationBuilder application)
因此,当将应用程序部署在JEE Servlet容器中时,Spring Boot应用程序将被正确部署并提供服务。
例
@Configuration public class AppServletInitializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class); } }
的
Application.class
是相同的类中SpringApplication.run(Application.class, args);
的主方法
-
Heroku上的Spring Boot Gradle应用程序:无法访问jarfile
2021-02-02 关注 0 浏览111 1答案
-
如何在Tomcat中部署Spring Integration应用程序?
2021-02-01 关注 0 浏览117 1答案
-
无法将Spring Boot应用程序部署到Azure
2021-02-02 关注 0 浏览98 1答案
-
在Tomcat中部署的Spring引导应用程序中,没有从@ExceptionHandler返回@ResponseBody
2021-02-02 关注 0 浏览91 1答案
-
在现有tomcat中部署我的应用程序
2021-02-01 关注 0 浏览89 1答案
-
从Eclipse运行时无法访问Tomcat 7 Manager应用程序
2021-02-01 关注 0 浏览112 1答案
-
在Tomcat中为Spring Boot应用程序访问externalize application.properties?
2021-02-02 关注 0 浏览73 1答案
-
如何在Tomcat服务器上部署Spring Boot Web应用程序
2021-02-02 关注 0 浏览154 1答案
-
如何显示在Tomcat中部署的应用程序的维护页面?
2021-02-01 关注 0 浏览100 1答案
-
在Weblogic中部署Spring Boot应用
2021-02-02 关注 0 浏览237 1答案