我有一个简单的Spring Boot应用程序,它从JMS队列获取消息并将一些数据保存到日志文件中,但不需要Web服务器.有没有办法在没有Web服务器的情况下启动Spring Boot?
我正在使用Spring Tool Suite在Spring上开发一个webapp.如果我使用IDE在所提供的Pivotal tc服务器上构建和部署应用程序,它就可以正常工作.但是,如果我执行手动"mvn clean package"构建并尝试将其部署到独立的Tomcat服务器(使用最新的Tomcat 7),则会引发以下异常:
2017-08-23 15:24:13 WARN AnnotationConfigWebApplicationContext:551 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Factory method 'requestMappingHandlerAdapter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcValidator' defined in org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/el/ELManager
2017-08-23 15:24:13 ERROR DispatcherServlet:502 - Context initialization …Run Code Online (Sandbox Code Playgroud) 概观
我可以使用spring-boot的maven插件运行应用程序,但不能使用IDE运行它.以下几行详细介绍了我的程序.
应用程序类如下:
package com.blss.retailServices.dataExportRouter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.velocity.VelocityAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan
@EnableAutoConfiguration(exclude = { VelocityAutoConfiguration.class })
public class DataExportRouterApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(DataExportRouterApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
异常堆栈跟踪如下:
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at …Run Code Online (Sandbox Code Playgroud) 我想从Spring Boot应用程序创建一个war文件,我可以将其部署到一个独立的Tomcat容器,而不是使用嵌入式容器.
我可以创建war文件并使用它自己运行它"java -jar pdfjs-annotator.war"并且它工作正常.
我使用gradle bootRepackage(Using Gradle,Tomcat7,Java 1.7)构建了应用程序.
但是当我将war文件部署到独立的Tomcat并启动它时,应用程序似乎根据日志启动时没有错误,但我无法访问任何资源,也无法控制器URL工作.
例如,我的index.html是src/main/resources/static/index.html下的静态html页面,我通常可以通过localhost:8080/index.html调用,但是当部署到独立的Tomcat时,页面会执行没有通过相同的URL传递(它在WEB-INF/classes/static/index.html中的war文件中).而且任何类型的控制器映射似乎都不起作用.我收到了404错误.
的build.gradle:
buildscript {
ext {
springBootVersion = '1.2.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.spring.gradle:dependency-management-plugin:0.5.0.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
war {
baseName = 'pdfjs-annotator'
version = '1.0.0-SNAPSHOT'
}
allprojects {
apply plugin: 'java'
sourceCompatibility = 1.6
targetCompatibility = 1.6
}
repositories {
mavenCentral()
} …Run Code Online (Sandbox Code Playgroud) 我的Tomcat status code 404上部署的每个应用程序都会在我发出的每个请求中返回 我尝试过几个项目,helloworlds或者骷髅,每个项目的行为与其他项目相同:
我用过的一些项目:
https://github.com/mwarman/skeleton-ws-spring-boot
https://spring.io/guides/gs/rest-service/(我可以运行它,mvn spring-boot:run但它不能部署到Tomcat)
https://github.com/shagstrom/spring-mvc-hibernate-skeleton
我正在使用最新的Tomcat8 (8.0.27),Oracle JDK 8.我也试过Tomcat7了OpenJDK 7.使用的Tomcats在MAC和Debian上运行.我通过mvn和Intellij Idea构建应用程序.
Tomcats很干净,没有更改配置(除了添加manager-gui用户).
由于我尝试了很多不同的项目,我不相信代码中存在问题.它是在Tomcat的配置中吗?我怎样才能让它发挥作用?
编辑:
server.xml代码:
<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" …Run Code Online (Sandbox Code Playgroud)