如何使 Spring 启动应用程序可部署在 TomEE 7.x 上?

How to make Spring Boot app deployable on TomEE 7.x?

我有一个简单的 Spring 引导 Web 应用程序。 https://gist.github.com/IvanZelenskyy/90f554276c6b3665f11368c7152ae97e

我有一个 Tomcat 8.x 和 TomEE 7.x 服务器,两者都具有默认配置。 当我将我的应用程序(如 war)部署到 Tomcat(以及 Glassfish)时,它工作正常。但是当我尝试将这个 war 部署到 TomEE 时,我在日志中遇到了很多异常:

07-Sep-2018 14:05:45.627 INFO [localhost-startStop-2] sun.reflect.DelegatingMethodAccessorImpl.invoke Deploying web application archive [/home/ivan/apache-tomee-plume-7.0.5/webapps/demotomee1.war]
07-Sep-2018 14:05:45.629 INFO [localhost-startStop-2] org.apache.tomee.catalina.TomcatWebAppBuilder.init ------------------------- localhost -> /demotomee1
07-Sep-2018 14:05:45.633 INFO [localhost-startStop-2] org.apache.openejb.util.JarExtractor.extract Extracting jar: /home/ivan/apache-tomee-plume-7.0.5/webapps/demotomee1.war
07-Sep-2018 14:05:45.744 INFO [localhost-startStop-2] org.apache.openejb.util.JarExtractor.extract Extracted path: /home/ivan/apache-tomee-plume-7.0.5/webapps/demotomee1
07-Sep-2018 14:05:46.180 INFO [localhost-startStop-2] org.apache.openejb.config.ConfigurationFactory.configureApplication Configuring enterprise application: /home/ivan/apache-tomee-plume-7.0.5/webapps/demotomee1
07-Sep-2018 14:05:46.402 INFO [localhost-startStop-2] org.apache.openejb.config.ConfigurationFactory.configureService Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
07-Sep-2018 14:05:46.403 INFO [localhost-startStop-2] org.apache.openejb.config.AutoConfig.createContainer Auto-creating a container for bean demotomee1.Comp1226937296: Container(type=MANAGED, id=Default Managed Container)
07-Sep-2018 14:05:46.403 INFO [localhost-startStop-2] org.apache.openejb.assembler.classic.Assembler.createRecipe Creating Container(id=Default Managed Container)
07-Sep-2018 14:05:46.429 INFO [localhost-startStop-2] org.apache.openejb.core.managed.SimplePassivater.init Using directory /home/ivan/apache-tomee-plume-7.0.5/temp for stateful session passivation
07-Sep-2018 14:05:46.478 INFO [localhost-startStop-2] org.apache.openejb.config.AppInfoBuilder.build Enterprise application "/home/ivan/apache-tomee-plume-7.0.5/webapps/demotomee1" loaded.
07-Sep-2018 14:05:46.478 INFO [localhost-startStop-2] org.apache.openejb.assembler.classic.Assembler.createApplication Assembling app: /home/ivan/apache-tomee-plume-7.0.5/webapps/demotomee1
14:05:46.915 [localhost-startStop-2] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Log4j2LoggerProvider
07-Sep-2018 14:05:46.988 INFO [localhost-startStop-2] org.apache.openejb.assembler.classic.Assembler.destroyApplication Undeploying app: /home/ivan/apache-tomee-plume-7.0.5/webapps/demotomee1
07-Sep-2018 14:05:46.993 SEVERE [localhost-startStop-2] sun.reflect.NativeMethodAccessorImpl.invoke ContainerBase.removeChild: destroy: 
 org.apache.catalina.LifecycleException: An invalid Lifecycle transition was attempted ([before_destroy]) for component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/demotomee1]] in state [STARTING_PREP]
    at org.apache.catalina.util.LifecycleBase.invalidTransition(LifecycleBase.java:402)
    at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:292)
    at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:856)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.undeploy(TomcatWebAppBuilder.java:1651)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.undeploy(TomcatWebAppBuilder.java:1631)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.undeployWebApps(TomcatWebAppBuilder.java:764)
    at org.apache.openejb.assembler.classic.Assembler.destroyApplication(Assembler.java:2374)
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:1092)
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:757)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1303)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1125)
    at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:133)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

07-Sep-2018 14:05:47.137 SEVERE [localhost-startStop-2] org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal Unable to deploy collapsed ear in war StandardEngine[Catalina].StandardHost[localhost].StandardContext[/demotomee1]
 org.apache.openejb.OpenEJBException: Creating application failed: /home/ivan/apache-tomee-plume-7.0.5/webapps/demotomee1: javax.validation.spi.ConfigurationState.getValueExtractors()Ljava/util/Set;
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:1096)
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:757)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1303)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1125)
    at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:133)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoSuchMethodError: javax.validation.spi.ConfigurationState.getValueExtractors()Ljava/util/Set;
    at org.hibernate.validator.internal.engine.ValidatorFactoryImpl.<init>(ValidatorFactoryImpl.java:140)
    at org.hibernate.validator.HibernateValidator.buildValidatorFactory(HibernateValidator.java:38)
    at org.apache.bval.jsr.ConfigurationImpl.__privileged_doBuildValidatorFactory(ConfigurationImpl.java:332)
    at org.apache.bval.jsr.ConfigurationImpl.doBuildValidatorFactory(ConfigurationImpl.java)
    at org.apache.bval.jsr.ConfigurationImpl.buildValidatorFactory(ConfigurationImpl.java:324)
    at org.apache.openejb.assembler.classic.ValidatorBuilder$OpenEjbConfig.buildValidatorFactory(ValidatorBuilder.java:401)
    at org.apache.openejb.assembler.classic.ValidatorBuilder.buildFactory(ValidatorBuilder.java:111)
    at org.apache.openejb.assembler.classic.ValidatorBuilder.buildFactory(ValidatorBuilder.java:67)
    at org.apache.openejb.assembler.classic.LazyValidatorFactory.ensureDelegate(LazyValidatorFactory.java:54)
    at org.apache.openejb.assembler.classic.LazyValidatorFactory.getFactory(LazyValidatorFactory.java:65)
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:975)
    ... 17 more

07-Sep-2018 14:05:47.138 SEVERE [localhost-startStop-2] sun.reflect.NativeMethodAccessorImpl.invoke ContainerBase.addChild: start: 
 org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/demotomee1]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.tomee.catalina.TomEERuntimeException: org.apache.openejb.OpenEJBException: Creating application failed: /home/ivan/apache-tomee-plume-7.0.5/webapps/demotomee1: javax.validation.spi.ConfigurationState.getValueExtractors()Ljava/util/Set;
    at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1315)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1125)
    at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:133)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 10 more
Caused by: org.apache.openejb.OpenEJBException: Creating application failed: /home/ivan/apache-tomee-plume-7.0.5/webapps/demotomee1: javax.validation.spi.ConfigurationState.getValueExtractors()Ljava/util/Set;
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:1096)
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:757)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1303)
    ... 15 more
Caused by: java.lang.NoSuchMethodError: javax.validation.spi.ConfigurationState.getValueExtractors()Ljava/util/Set;
    at org.hibernate.validator.internal.engine.ValidatorFactoryImpl.<init>(ValidatorFactoryImpl.java:140)
    at org.hibernate.validator.HibernateValidator.buildValidatorFactory(HibernateValidator.java:38)
    at org.apache.bval.jsr.ConfigurationImpl.__privileged_doBuildValidatorFactory(ConfigurationImpl.java:332)
    at org.apache.bval.jsr.ConfigurationImpl.doBuildValidatorFactory(ConfigurationImpl.java)
    at org.apache.bval.jsr.ConfigurationImpl.buildValidatorFactory(ConfigurationImpl.java:324)
    at org.apache.openejb.assembler.classic.ValidatorBuilder$OpenEjbConfig.buildValidatorFactory(ValidatorBuilder.java:401)
    at org.apache.openejb.assembler.classic.ValidatorBuilder.buildFactory(ValidatorBuilder.java:111)
    at org.apache.openejb.assembler.classic.ValidatorBuilder.buildFactory(ValidatorBuilder.java:67)
    at org.apache.openejb.assembler.classic.LazyValidatorFactory.ensureDelegate(LazyValidatorFactory.java:54)
    at org.apache.openejb.assembler.classic.LazyValidatorFactory.getFactory(LazyValidatorFactory.java:65)
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:975)
    ... 17 more

07-Sep-2018 14:05:47.138 SEVERE [localhost-startStop-2] sun.reflect.NativeMethodAccessorImpl.invoke Error deploying web application archive [/home/ivan/apache-tomee-plume-7.0.5/webapps/demotomee1.war]
 java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/demotomee1]]
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:758)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

07-Sep-2018 14:05:47.138 INFO [localhost-startStop-2] sun.reflect.DelegatingMethodAccessorImpl.invoke Deployment of web application archive [/home/ivan/apache-tomee-plume-7.0.5/webapps/demotomee1.war] has finished in [1,511] ms

如何在 TomEE 上启动我的应用程序?

我遇到了同样的问题。我能够在 TomEE 上获得一个工作的 Spring 启动应用程序,它在 pom.xml:

中依赖和排除 hibernate-validator
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.hibernate.validator</groupId>
                <artifactId>hibernate-validator</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.apache.tomee</groupId>
        <artifactId>apache-tomee</artifactId>
        <version>7.X.X</version>
    </dependency>