it-swarm.com.ru

Не удалось запустить приложение Spring-Boot

Я создал базовое приложение для весенней загрузки с контейнером Tomcat. После сборки jar с помощью maven я запускаю его как 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);
    }
}
2
Saveendra Ekanayake

Вам необходимо внести следующие изменения в файл pom.xml, если вы хотите развернуть войну в Tomcat.

       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 является контейнером по умолчанию для приложения весенней загрузки, вам не нужно явно указывать зависимости Tomcat. Я бы порекомендовал и настоятельно рекомендую вам использовать Spring Initializer , чтобы начать работу с приложением весенней загрузки.

Могу ли я узнать, почему класс вашего приложения расширяется от SpringBootServletInitializer? Планируете ли вы сделать горячее развертывание.?

0
Lovababu