web-dev-qa-db-ja.com

Spring-Bootアプリケーションの起動に失敗しました

Tomcatコンテナーで基本的なSpring-Bootアプリケーションを作成しました。 mavenを使用してjarをビルドした後、Java -jar mybootapp-1.0.0.jarとして実行します。その後、以下のエラーが発生しました。 mvn spring-boot:runコマンドを使用してアプリを実行する方法。しかし、通常のjarファイルの実行でエラーが発生する理由は何ですか。

スタックトレース

2016-12-28 07:43:27.945  WARN 11564 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcatEmbeddedServletContainerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.HttpEncodingAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.http.encoding-org.springframework.boot.autoconfigure.web.HttpEncodingProperties': Initialization of bean failed; nested exception is Java.lang.NoClassDefFoundError: javax/xml/bind/ValidationException
    2016-12-28 07:43:27.983 ERROR 11564 --- [           main] o.s.boot.SpringApplication               : Application startup failed

    org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcatEmbeddedServletContainerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.HttpEncodingAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.http.encoding-org.springframework.boot.autoconfigure.web.HttpEncodingProperties': Initialization of bean failed; nested exception is Java.lang.NoClassDefFoundError: javax/xml/bind/ValidationException
            at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.Java:137) ~[spring-boot-1.4.3.RELEASE.jar!/:1.4.3.RELEASE]
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:536) ~[spring-context-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
            at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.Java:122) ~[spring-boot-1.4.3.RELEASE.jar!/:1.4.3.RELEASE]
            at org.springframework.boot.SpringApplication.refresh(SpringApplication.Java:761) [spring-boot-1.4.3.RELEASE.jar!/:1.4.3.RELEASE]
            at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.Java:371) [spring-boot-1.4.3.RELEASE.jar!/:1.4.3.RELEASE]
            at org.springframework.boot.SpringApplication.run(SpringApplication.Java:315) [spring-boot-1.4.3.RELEASE.jar!/:1.4.3.RELEASE]
            at org.springframework.boot.SpringApplication.run(SpringApplication.Java:1186) [spring-boot-1.4.3.RELEASE.jar!/:1.4.3.RELEASE]
            at org.springframework.boot.SpringApplication.run(SpringApplication.Java:1175) [spring-boot-1.4.3.RELEASE.jar!/:1.4.3.RELEASE]
            at com.mybootapp.Application.main(Application.Java:25) [classes!/:1.0.0]
            at Java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
            at Java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62) ~[na:na]
            at Java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43) ~[na:na]
            at Java.base/Java.lang.reflect.Method.invoke(Method.Java:537) ~[na:na]
            at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.Java:48) [mybootapp-1.0.0.jar:1.0.0]
            at org.springframework.boot.loader.Launcher.launch(Launcher.Java:87) [mybootapp-1.0.0.jar:1.0.0]
            at org.springframework.boot.loader.Launcher.launch(Launcher.Java:50) [mybootapp-1.0.0.jar:1.0.0]
            at org.springframework.boot.loader.JarLauncher.main(JarLauncher.Java:51) [mybootapp-1.0.0.jar:1.0.0]
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcatEmbeddedServletContainerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.HttpEncodingAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.http.encoding-org.springframework.boot.autoconfigure.web.HttpEncodingProperties': Initialization of bean failed; nested exception is Java.lang.NoClassDefFoundError: javax/xml/bind/ValidationException
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:563) ~[spring-beans-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:483) ~[spring-beans-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:306) ~[spring-beans-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:230) ~[spring-beans-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:302) ~[spring-beans-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:202) ~[spring-beans-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
            at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.Java:199) ~[spring-boot-1.4.3.RELEASE.jar!/:1.4.3.RELEASE]
            at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.Java:162) ~[spring-boot-1.4.3.RELEASE.jar!/:1.4.3.RELEASE]
            at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.Java:134) ~[spring-boot-1.4.3.RELEASE.jar!/:1.4.3.RELEASE]
            ... 16 common frames omitted
    Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.HttpEncodingAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.http.encoding-org.springframework.boot.autoconfigure.web.HttpEncodingProperties': Initialization of bean failed; nested exception is Java.lang.NoClassDefFoundError: javax/xml/bind/ValidationException

POMファイル

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mybootapp</groupId>
    <artifactId>mybootapp</artifactId>
    <version>1.0.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.RELEASE</version>
    </parent>

    <dependencies>
        <!-- Web application -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- Tomcat embedded container-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-Tomcat</artifactId>
        </dependency>
        <!-- Need this to compile JSP -->
        <dependency>
            <groupId>org.Apache.Tomcat.embed</groupId>
            <artifactId>Tomcat-embed-jasper</artifactId>
        </dependency>
        <!-- JSTL for JSP -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <properties>
        <Java.version>1.8</Java.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

メインクラス

package com.mybootapp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;


@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }


    public static void main(String[] args) throws Exception{
        SpringApplication.run(Application.class, args);
    }
}
5

Tomcatにwarをデプロイする場合は、pom.xmlファイルに以下の変更を加える必要があります。

       1) In pom.xml file , make scope as provided for embedded server 

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-undertow</artifactId>
              <scope>provided</scope>
        </dependency>

         or

     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-Tomcat</artifactId>
        <scope>provided</scope>
     </dependency>

     2) In pom.xml file, make packaging as war

         <packaging>war</packaging>
1
Subhasish Sahu

1.4.3。RELEASEが現在ミラーから欠落しているようです

https://repo.maven.Apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/

1.4.2のみになります

0
Jason

TomcatサーバーはSpring Bootアプリケーションのデフォルトのコンテナーであるため、Tomcatの依存関係を明示的に指定する必要はありません。 Spring Initializer を使用してスプリングブートアプリケーションを開始することをお勧めします。

アプリケーションクラスがSpringBootServletInitializerから拡張される理由を教えてください。ホットデプロイメントを行う予定ですか?

0
Lovababu