我有一个Spring启动应用程序,我试图在Tomcat服务器上部署它。 当我在eclipse中本地运行应用程序时,它已成功部署。但是当我尝试在Linux tomcat服务器上部署时。它失败。我不确定配置有什么问题。 我试图将war文件放在tomcat webapps文件夹下并运行startup.bat文件。但它继续运行日志跟踪。 请建议我应该尝试什么。
的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hc.medley</groupId>
<artifactId>MedleyBackend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
</parent>
<name>MedleyBackend</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<springframework.version>4.2.5.RELEASE</springframework.version>
<hibernate.version>4.3.6.Final</hibernate.version>
<jackson.version>2.5.3</jackson.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.19</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin><!-- Include if you want to make an executable jar[FAT JAR which
includes all dependencies along with sprinboot loader] that you can run on
commandline using java -jar NAME -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<executable>${JAVA_1_8_HOME}/bin/javac</executable>
</configuration>
</plugin>
</plugins>
<finalName>Medley</finalName>
</build>
来自服务器日志的最后几行
2018-02-27 19:25:29.736 INFO 14224 --- [localhost-startStop-1] c.m.medley.controller.Application : Starting Application v1.0 on DC01SPBIAPPDV06 with PID 14224 (started by singhma1 in C:\apache-tomcat-8.5.27\apache-tomcat-8.5.27\bin)
2018-02-27 19:25:29.751 INFO 14224 --- [localhost-startStop-1] c.m.medley.controller.Application : No active profile set, falling back to default profiles: default
2018-02-27 19:25:29.829 INFO 14224 --- [localhost-startStop-1] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@153860ce: startup date [Tue Feb 27 19:25:29 PST 2018]; root of context hierarchy
2018-02-27 19:25:31.454 INFO 14224 --- [localhost-startStop-1] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$15e9d470] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-02-27 19:25:31.548 INFO 14224 --- [localhost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1719 ms
2018-02-27 19:25:32.282 INFO 14224 --- [localhost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2018-02-27 19:25:32.282 INFO 14224 --- [localhost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'errorPageFilter' to: [/*]
2018-02-27 19:25:32.282 INFO 14224 --- [localhost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-02-27 19:25:32.564 INFO 14224 --- [localhost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/],methods=[GET]}" onto public java.lang.String com.aimcare.medley.controller.IndexController.getIndexPage()
2018-02-27 19:25:32.564 INFO 14224 --- [localhost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/items/memberPage]}" onto public java.lang.String com.aimcare.medley.controller.MainTemplateController.getMemberPageTemplate()
2018-02-27 19:25:32.564 INFO 14224 --- [localhost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/items/editMemberPage]}" onto public java.lang.String com.aimcare.medley.controller.MainTemplateController.getMemberEditPageTemplate()
2018-02-27 19:25:32.564 INFO 14224 --- [localhost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/items/landingPage]}" onto public java.lang.String com.aimcare.medley.controller.MainTemplateController.getLandingPageTemplate()
2018-02-27 19:25:32.564 INFO 14224 --- [localhost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[GET],produces=[application/json]}" onto public java.util.List<com.aimcare.medley.model.Members> com.aimcare.medley.controller.SpringController.error() throws java.lang.Exception
2018-02-27 19:25:32.579 INFO 14224 --- [localhost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/getMemberDetails/{memberId:.*}/{state:.*}],methods=[GET],produces=[application/json]}" onto public java.util.List<com.aimcare.medley.model.MedleyMemberDetail> com.aimcare.medley.controller.SpringController.getMemberDetails(java.lang.String,java.lang.String) throws java.lang.Exception
2018-02-27 19:25:32.579 INFO 14224 --- [localhost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/getUserList],methods=[GET],produces=[application/json]}" onto public java.util.List<com.aimcare.medley.model.Members> com.aimcare.medley.controller.SpringController.getUserList() throws java.lang.Exception
2018-02-27 19:25:32.579 INFO 14224 --- [localhost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/getUserbyState/{state:.*}],methods=[GET],produces=[application/json]}" onto public java.util.List<com.aimcare.medley.model.Members> com.aimcare.medley.controller.SpringController.getUserbyState(java.lang.String) throws java.lang.Exception
2018-02-27 19:25:32.579 INFO 14224 --- [localhost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/addMemberContact],methods=[POST],produces=[application/json]}" onto public com.aimcare.medley.model.Member com.aimcare.medley.controller.SpringController.addMemberContact(com.aimcare.medley.model.Member)
2018-02-27 19:25:32.579 INFO 14224 --- [localhost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/addMemberCallDetail],methods=[POST],produces=[application/json]}" onto public com.aimcare.medley.model.Member com.aimcare.medley.controller.SpringController.addMemberDetail(com.aimcare.medley.model.Member)
2018-02-27 19:25:32.595 INFO 14224 --- [localhost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-02-27 19:25:32.595 INFO 14224 --- [localhost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-02-27 19:25:32.642 INFO 14224 --- [localhost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/static/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-02-27 19:25:32.736 INFO 14224 --- [localhost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@153860ce: startup date [Tue Feb 27 19:25:29 PST 2018]; root of context hierarchy
2018-02-27 19:25:33.439 INFO 14224 --- [localhost-startStop-1] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-02-27 19:25:33.454 INFO 14224 --- [localhost-startStop-1] c.m.medley.controller.Application : Started Application in 4.781 seconds (JVM running for 8.579)
2018-02-27 19:25:33.470 INFO 14224 --- [localhost-startStop-1] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@153860ce: startup date [Tue Feb 27 19:25:29 PST 2018]; root of context hierarchy
2018-02-27 19:25:33.470 INFO 14224 --- [localhost-startStop-1] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
答案 0 :(得分:0)
能够在您已经完成的工作之上创建可部署的war文件;
1)你的main(Application类)应该扩展SpringBootServletInitializer并覆盖configure方法,如下所示:
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
2)在你的pom文件中,你应该为tomcat添加一个提供的依赖项,以防止嵌入式容器干扰外部容器:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
添加这些后,它应该可以正常工作。