当前位置: 首页 > 知识库问答 >
问题:

如何将spring-boot WAR部署到Tomcat?

居焱
2023-03-14

我有一个spring-boot应用程序,它很好地作为一个JAR运行,但是当我试图将它转换为一个WAR时,我无法部署它。

我试着为它寻找规则,以决定它的Tomcat是嵌入式的还是外部的。

web-inf/lib和web-inf/lib提供的WAR看起来是正确的,没有明显放错位置的jar。

我的应用程序类扩展了SpringBootServletInitializer。调试时,此类将应用程序上下文类设置为AnnotationConfigEmbeddedWebApplicationContext.class...这是正确的吗?

当尝试部署为WAR时,我应该期待看到嵌入类被加载吗?

我使用的是:-

1)spring framework 4.1.2.Release 2)spring-boot 1.1.9.Release 3)spring security 3.2.5.Release 4)Tomcat 7.0.57

应用程序同时使用WebMvc和WebSockets...

问候

我的父母POM

<dependencyManagement>
    ....
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>${spring.boot.version}</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>
    ....
</dependencyManagement>
    <!-- Spring Boot -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-websocket</artifactId>
        <!-- WebSocket Latest -->
        <!--<version>1.2.0.RC1</version>-->
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-websocket</artifactId>
        <scope>provided</scope>
    </dependency>
    <!--
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
    -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    <!-- Spring Boot Security -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
....
123143 [RMI TCP Connection(2)-127.0.0.1] DEBUG o.s.b.c.c.ConfigFileApplicationListener - Skipped config file 'classpath:/application.yaml' for profile resource not found
123143 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@54d9aaa1: startup date [Wed Dec 03 09:13:08 GMT 2014]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@2c6debf9
123190 [RMI TCP Connection(2)-127.0.0.1] DEBUG o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Bean factory for org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@54d9aaa1: org.springframework.beans.factory.support.DefaultListableBeanFactory@10dbb363: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,play.application,errorPageFilter]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@3d5e51e5
141940 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.b.f.xml.XmlBeanDefinitionReader - Loading XML bean definitions from URL [jar:file:/E:/Software/Servers/apache-tomcat-7.0.57/webapps/ROOT/WEB-INF/lib/cf_shared-1.0-SNAPSHOT.jar!/spring/beanRefContext.xml]
142065 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.b.f.xml.XmlBeanDefinitionReader - Loading XML bean definitions from URL [jar:file:/E:/Software/Servers/apache-tomcat-7.0.57/webapps/ROOT/WEB-INF/lib/cf_shared-1.0-SNAPSHOT.jar!/spring/globalApplicationContext.xml]
142174 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.b.f.xml.XmlBeanDefinitionReader - Loading XML bean definitions from URL [jar:file:/E:/Software/Servers/apache-tomcat-7.0.57/webapps/ROOT/WEB-INF/lib/cf_shared-1.0-SNAPSHOT.jar!/spring/globalApplicationContext-configuration.xml]
142455 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.b.f.s.DefaultListableBeanFactory - Overriding bean definition for bean 'org.springframework.boot.autoconfigure.AutoConfigurationPackages': replacing [Generic bean: class [org.springframework.boot.autoconfigure.AutoConfigurationPackages$BasePackages]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.springframework.boot.autoconfigure.AutoConfigurationPackages$BasePackages]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
146518 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.b.f.s.DefaultListableBeanFactory - Overriding bean definition for bean 'beanNameViewResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
162564 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'async' of type [class com.cf.play.config.Async$$EnhancerBySpringCGLIB$$dd119135] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
162939 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.s.c.ThreadPoolTaskExecutor - Initializing ExecutorService  'getAsyncExecutor'
162939 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'getAsyncExecutor' of type [class org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
162939 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration' of type [class org.springframework.scheduling.annotation.ProxyAsyncConfiguration$$EnhancerBySpringCGLIB$$7617ce05] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
164892 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration' of type [class org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration$$EnhancerBySpringCGLIB$$6c9aa01e] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
165611 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'objectPostProcessor' of type [class org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
165642 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@41b21e0a' of type [class org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
167330 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'security.AuthenticationConfiguration' of type [class com.cf.play.config.Security$AuthenticationConfiguration$$EnhancerBySpringCGLIB$$f014df73] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
168111 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration' of type [class org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration$$EnhancerBySpringCGLIB$$fe30e14e] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
169814 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'securityProperties' of type [class org.springframework.boot.autoconfigure.security.SecurityProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
170861 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.boot.autoconfigure.security.AuthenticationManagerConfiguration' of type [class org.springframework.boot.autoconfigure.security.AuthenticationManagerConfiguration$$EnhancerBySpringCGLIB$$538cd08c] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
171392 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.b.f.xml.XmlBeanDefinitionReader - Loading XML bean definitions from URL [jar:file:/E:/Software/Servers/apache-tomcat-7.0.57/webapps/ROOT/WEB-INF/lib/cf_shared-1.0-SNAPSHOT.jar!/spring/globalApplicationContext-configuration.xml]
171502 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.b.f.xml.XmlBeanDefinitionReader - Loading XML bean definitions from URL [jar:file:/E:/Software/Servers/apache-tomcat-7.0.57/webapps/ROOT/WEB-INF/lib/cf_shared-1.0-SNAPSHOT.jar!/spring/globalApplicationContext-security.xml]
171908 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.s.c.SpringSecurityCoreVersion - You are running with Spring Security Core 3.2.5.RELEASE
171939 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.s.c.SecurityNamespaceHandler - Spring Security 'config' module version is 3.2.5.RELEASE
172267 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.b.f.xml.XmlBeanDefinitionReader - Loading XML bean definitions from URL [jar:file:/E:/Software/Servers/apache-tomcat-7.0.57/webapps/ROOT/WEB-INF/lib/cf_shared-1.0-SNAPSHOT.jar!/spring/globalApplicationContext.xml]
172377 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.c.s.GenericXmlApplicationContext - Refreshing org.springframework.context.support.GenericXmlApplicationContext@7b50e9c5: startup date [Wed Dec 03 09:13:57 GMT 2014]; root of context hierarchy
172705 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.c.e.EhCacheManagerFactoryBean - Initializing EhCache CacheManager
174923 [RMI TCP Connection(2)-127.0.0.1] INFO  org.quartz.impl.StdSchedulerFactory - Using default implementation for ThreadExecutor
175048 [RMI TCP Connection(2)-127.0.0.1] INFO  o.quartz.core.SchedulerSignalerImpl - Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
175048 [RMI TCP Connection(2)-127.0.0.1] INFO  org.quartz.core.QuartzScheduler - Quartz Scheduler v.2.2.1 created.
175064 [RMI TCP Connection(2)-127.0.0.1] INFO  org.quartz.simpl.RAMJobStore - RAMJobStore initialized.
175064 [RMI TCP Connection(2)-127.0.0.1] INFO  org.quartz.core.QuartzScheduler - Scheduler meta-data: Quartz Scheduler (v2.2.1) 'CAS ProxyGrantingTicketStorage Scheduler' with instanceId 'NON_CLUSTERED'
  Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
  Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.

175064 [RMI TCP Connection(2)-127.0.0.1] INFO  org.quartz.impl.StdSchedulerFactory - Quartz scheduler 'CAS ProxyGrantingTicketStorage Scheduler' initialized from an externally provided properties instance.
175064 [RMI TCP Connection(2)-127.0.0.1] INFO  org.quartz.impl.StdSchedulerFactory - Quartz scheduler version: 2.2.1
175080 [RMI TCP Connection(2)-127.0.0.1] INFO  org.quartz.core.QuartzScheduler - JobFactory set to: org.springframework.scheduling.quartz.AdaptableJobFactory@24917741
175111 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.c.s.DefaultLifecycleProcessor - Starting beans in phase 2147483647
175111 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.s.quartz.SchedulerFactoryBean - Starting Quartz Scheduler now
175111 [RMI TCP Connection(2)-127.0.0.1] INFO  org.quartz.core.QuartzScheduler - Scheduler CAS ProxyGrantingTicketStorage Scheduler_$_NON_CLUSTERED started.
175330 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'globalParentApplicationContext' of type [class org.springframework.context.support.GenericXmlApplicationContext] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
175392 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration' of type [class org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration$$EnhancerBySpringCGLIB$$61dc3bd3] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
176486 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration' of type [class org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration$$EnhancerBySpringCGLIB$$f4cff750] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
176658 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'methodSecurityMetadataSource' of type [class org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
176736 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'metaDataSourceAdvisor' of type [class org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
176767 [RMI TCP Connection(2)-127.0.0.1] DEBUG o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@10a32452]
176783 [RMI TCP Connection(2)-127.0.0.1] DEBUG o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Using ApplicationEventMulticaster [org.springframework.context.event.SimpleApplicationEventMulticaster@774aa541]
323644 [RMI TCP Connection(2)-127.0.0.1] DEBUG o.s.b.c.e.t.TomcatEmbeddedServletContainerFactory - Code archive: E:\Software\Servers\apache-tomcat-7.0.57\webapps\ROOT\WEB-INF\lib\spring-boot-1.1.9.RELEASE.jar
323644 [RMI TCP Connection(2)-127.0.0.1] DEBUG o.s.b.c.e.t.TomcatEmbeddedServletContainerFactory - Code archive: E:\Software\Servers\apache-tomcat-7.0.57\webapps\ROOT\WEB-INF\lib\spring-boot-1.1.9.RELEASE.jar
323644 [RMI TCP Connection(2)-127.0.0.1] DEBUG o.s.b.c.e.t.TomcatEmbeddedServletContainerFactory - None of the document roots [src/main/webapp, public, static] point to a directory and will be ignored.
323660 [RMI TCP Connection(2)-127.0.0.1] INFO  o.s.b.c.e.t.TomcatEmbeddedServletContainerFactory - Server initialized with port: 8080
Dec 03, 2014 9:16:29 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Dec 03, 2014 9:16:29 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.57
Dec 03, 2014 9:16:29 AM org.apache.catalina.loader.WebappLoader startInternal
SEVERE: LifecycleException 
java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedWebappClassLoader
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:260)
    at org.apache.catalina.loader.WebappLoader.createClassLoader(WebappLoader.java:721)
    at org.apache.catalina.loader.WebappLoader.startInternal(WebappLoader.java:582)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5357)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

共有1个答案

皇甫智明
2023-03-14

好了,我发现问题了....配置

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application
            .showBanner(true)
            .parent(Global.class)
            .child(applicationClass)
            .profiles("container")
            ;
}

应该是...

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application
            .showBanner(true)
            .parent(Global.class)
            .sources(applicationClass)
            .profiles("container")
            ;
}

...我使用了child()而不是sources()...

 类似资料:
  • 目前,我的所有属性都定义在文件中。但是,我希望在文件夹中有与不同配置文件相关的属性文件,并且我希望能够选择其中的任何一个。例如: null

  • 所以我对Spring很陌生--所以我想试试Spring Boot 我正在使用一个Maven来构建--我设置了一个视图请求,当我以“app”的形式运行它时,看起来就像它自己启动了tomcat,并且我有一个默认8080端口的服务,所以当我调用时,一切都很好。 然而,当我试图将其打包为WAR部署到服务器时,它不起作用 所以我想我应该回到基础,并将它部署到本地的tomcat服务器上,看看会发生什么 所以首

  • 问题内容: 在尝试将新的portlet安装到在Glassfish域上运行的Liferay时遇到了问题。我最近很清楚流程,也想与他人分享。所以,请阅读答案,希望这对某人有帮助:) (此问题的先决条件是,我知道添加在 Glassfish 上运行的项目是通过autodeploy文件夹完成的,但是使它们在 Liferay上 可见则是另一回事了。) 问题答案: 因此,您首先创建一个.war文件,让我们说一个

  • 我想第一次使用docker发布我在spring boot中制作的应用程序。然而,在发布时出现了一个问题。 因此,我上传到conter的图像不显示。 以下是我采取的步骤,我将立即添加我使用gradle的步骤。 > 我将Docker插件下载到IntelliJ 我创建了一个Dockerfile,其中我放了: 音量 /tmp ARG JAR_文件 在终端中,我键入以下命令来构建项目: chmod 777

  • 我在AWS和Spring框架方面都是新手。 我已经建立了一个简单的网络程序遵循入门指南在Spring网站。另外,我已经使我的弹性豆茎应用程序和环境运行Tomcat8和Java8。我想要的是; null 我不明白的是,如果我使用Gradle'build'任务或'boot run'任务,生成的可执行jar文件可以正常工作。但是,如果我通过Gradle'war'任务构建一个war文件并将其放在本地Tom