运行springboot应用程序时出现问题

时间:2017-12-05 04:31:10

标签: java spring maven spring-boot build

我开发了一个springboot应用程序,我在启动应用程序时遇到了一个问题。

这是我运行应用程序时的错误的堆栈跟踪。

2017-12-04 19:39:28.713  INFO 67222 --- [  restartedMain] c.g.www.xxx.xxxWebApplication  : Starting xxxWebApplication onxxx.sea.corp.expecn.com with PID 67222 (/Users/xxxx/dev/trash/xxx/target/classes started by xxxx in /Users/xxx/dev/trash/xxxx)
2017-12-04 19:39:28.714 DEBUG 67222 --- [  restartedMain] c.g.www.xxx.xxxWebApplication  : Running with Spring Boot v1.5.8.RELEASE, Spring v4.3.12.RELEASE
2017-12-04 19:39:28.714  INFO 67222 --- [  restartedMain] c.g.www.xxx.xxxWebApplication  : The following profiles are active: dev
2017-12-04 19:39:28.910  INFO 67222 --- [  restartedMain] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@63e1e61: startup date [Mon Dec 04 19:39:28 PST 2017]; root of context hierarchy
2017-12-04 19:39:29.081  WARN 67222 --- [  restartedMain] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.xxx.www.xxx.xxxWebApplication]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.boot.web.support.SpringBootServletInitializer
2017-12-04 19:39:29.083 ERROR 67222 --- [  restartedMain] o.s.b.f.s.DefaultListableBeanFactory     : Destroy method on bean with name 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory' threw an exception

java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.context.annotation.AnnotationConfigApplicationContext@63e1e61: startup date [Mon Dec 04 19:39:28 PST 2017]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:414)
at org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:97)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.destroySingletons(FactoryBeanRegistrySupport.java:230)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968)

经过深入研究,有人建议删除我的POM中的一些依赖项。因此,我运行以下命令 mvn dependency:tree 来查看依赖关系树。查看依赖关系树,我不知道我必须删除哪些依赖项。

[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building xxx 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ xxx ---
[INFO] com.xxx.www:xxx:war:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.5.8.RELEASE:compile
[INFO] |  |  \- org.springframework.boot:spring-boot-starter-logging:jar:1.5.8.RELEASE:compile
[INFO] |  |     +- ch.qos.logback:logback-classic:jar:1.1.11:compile
[INFO] |  |     |  \- ch.qos.logback:logback-core:jar:1.1.11:compile
[INFO] |  |     +- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |  |     \- org.slf4j:log4j-over-slf4j:jar:1.7.25:compile
[INFO] |  \- org.springframework.boot:spring-boot-actuator:jar:1.5.8.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:1.5.8.RELEASE:compile
[INFO] |  |  \- org.aspectj:aspectjweaver:jar:1.8.11:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.5.8.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat:tomcat-jdbc:jar:8.5.23:compile
[INFO] |  |  |  \- org.apache.tomcat:tomcat-juli:jar:8.5.23:compile
[INFO] |  |  \- org.springframework:spring-jdbc:jar:4.3.12.RELEASE:compile
[INFO] |  +- org.hibernate:hibernate-core:jar:5.0.12.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.1.Final:compile
[INFO] |  |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  |  +- org.javassist:javassist:jar:3.21.0-GA:compile
[INFO] |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  +- org.jboss:jandex:jar:2.0.0.Final:compile
[INFO] |  |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
[INFO] |  +- org.hibernate:hibernate-entitymanager:jar:5.0.12.Final:compile
[INFO] |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:1.11.8.RELEASE:compile
[INFO] |  |  +- org.springframework.data:spring-data-commons:jar:1.13.8.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-orm:jar:4.3.12.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-tx:jar:4.3.12.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-beans:jar:4.3.12.RELEASE:compile
[INFO] |  |  +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] |  |  \- org.slf4j:jcl-over-slf4j:jar:1.7.25:compile
[INFO] |  \- org.springframework:spring-aspects:jar:4.3.12.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-security:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.3.12.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-config:jar:4.2.3.RELEASE:compile
[INFO] |  |  \- org.springframework.security:spring-security-core:jar:4.2.3.RELEASE:compile
[INFO] |  \- org.springframework.security:spring-security-web:jar:4.2.3.RELEASE:compile
[INFO] |     \- org.springframework:spring-expression:jar:4.3.12.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-thymeleaf:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.thymeleaf:thymeleaf-spring4:jar:2.1.5.RELEASE:compile
[INFO] |  |  \- org.thymeleaf:thymeleaf:jar:2.1.5.RELEASE:compile
[INFO] |  |     +- ognl:ognl:jar:3.0.8:compile
[INFO] |  |     \- org.unbescape:unbescape:jar:1.1.0.RELEASE:compile
[INFO] |  \- nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:jar:1.4.0:compile
[INFO] |     \- org.codehaus.groovy:groovy:jar:2.4.12:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.hibernate:hibernate-validator:jar:5.3.5.Final:compile
[INFO] |  |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |  \- com.fasterxml:classmate:jar:1.3.4:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.10:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.8.10:compile
[INFO] |  +- org.springframework:spring-web:jar:4.3.12.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:4.3.12.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.5.8.RELEASE:provided
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.23:provided
[INFO] |  |  \- org.apache.tomcat:tomcat-annotations-api:jar:8.5.23:provided
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.23:provided
[INFO] |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.23:provided
[INFO] +- org.springframework.session:spring-session-data-redis:jar:1.3.1.RELEASE:compile
[INFO] |  +- org.apache.commons:commons-pool2:jar:2.4.2:compile
[INFO] |  +- org.springframework.data:spring-data-redis:jar:1.8.8.RELEASE:compile
[INFO] |  |  +- org.springframework.data:spring-data-keyvalue:jar:1.2.8.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-oxm:jar:4.3.12.RELEASE:compile
[INFO] |  +- org.springframework.session:spring-session:jar:1.3.1.RELEASE:compile
[INFO] |  \- redis.clients:jedis:jar:2.9.0:compile
[INFO] +- org.springframework.boot:spring-boot-devtools:jar:1.5.8.RELEASE:runtime
[INFO] |  +- org.springframework.boot:spring-boot:jar:1.5.8.RELEASE:compile
[INFO] |  \- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.8.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-mail:jar:1.5.8.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:4.3.12.RELEASE:compile
[INFO] |  +- org.springframework:spring-context-support:jar:4.3.12.RELEASE:compile
[INFO] |  \- com.sun.mail:javax.mail:jar:1.5.6:compile
[INFO] |     \- javax.activation:activation:jar:1.1:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.5.8.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:1.5.8.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.5.8.RELEASE:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.2.0:test
[INFO] |  |  \- net.minidev:json-smart:jar:2.2.1:test
[INFO] |  |     \- net.minidev:accessors-smart:jar:1.1:test
[INFO] |  |        \- org.ow2.asm:asm:jar:5.0.3:test
[INFO] |  +- junit:junit:jar:4.12:test
[INFO] |  +- org.assertj:assertj-core:jar:2.6.0:test
[INFO] |  +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] |  |  \- org.objenesis:objenesis:jar:2.1:test
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.4.0:test
[INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] |  +- org.springframework:spring-core:jar:4.3.12.RELEASE:compile
[INFO] |  \- org.springframework:spring-test:jar:4.3.12.RELEASE:test
[INFO] +- org.webjars:bootstrap:jar:4.0.0-alpha.6:compile
[INFO] +- org.webjars:jquery:jar:3.2.1:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.44:runtime
[INFO] +- org.codehaus.janino:janino:jar:2.7.8:compile
[INFO] |  \- org.codehaus.janino:commons-compiler:jar:2.7.8:compile
[INFO] +- com.nulab-inc:zxcvbn:jar:1.2.3:compile
[INFO] +- biz.paluch.redis:lettuce:jar:3.5.0.Final:compile
[INFO] |  +- io.reactivex:rxjava:jar:1.1.6:compile
[INFO] |  +- io.netty:netty-common:jar:4.0.37.Final:compile
[INFO] |  +- io.netty:netty-transport:jar:4.0.37.Final:compile
[INFO] |  |  \- io.netty:netty-buffer:jar:4.0.37.Final:compile
[INFO] |  +- io.netty:netty-handler:jar:4.0.37.Final:compile
[INFO] |  |  \- io.netty:netty-codec:jar:4.0.37.Final:compile
[INFO] |  \- com.google.guava:guava:jar:17.0:compile
[INFO] +- com.mmnaseri.utils:spring-data-mock:jar:1.1.4:test
[INFO] |  \- commons-logging:commons-logging:jar:1.2:test
[INFO] +- org.testng:testng:jar:6.9.6:test
[INFO] |  +- com.google.inject:guice:jar:no_aop:4.0:test
[INFO] |  |  +- javax.inject:javax.inject:jar:1:test
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:test
[INFO] |  +- org.beanshell:bsh:jar:2.0b4:test
[INFO] |  +- org.apache.ant:ant:jar:1.7.0:test
[INFO] |  |  \- org.apache.ant:ant-launcher:jar:1.7.0:test
[INFO] |  +- com.beust:jcommander:jar:1.48:test
[INFO] |  \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] \- org.hamcrest:hamcrest-all:jar:1.3:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.736 s
[INFO] Finished at: 2017-12-04T20:09:26-08:00
[INFO] Final Memory: 28M/437M
[INFO] ------------------------------------------------------------------------

请问有人就这个问题提出建议吗?

请在下面找到主要课程的一些代码

package com.xxx.www.xxx;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@SpringBootApplication
@ComponentScan("com.xxx.www.xxx")
@EntityScan("com.xxx.www.xxx.domain")
@EnableJpaRepositories("com.xxx.www.xxx.repository")a
@EnableAutoConfiguration(exclude = {ErrorMvcAutoConfiguration.class})
public class XXXWebApplication extends SpringBootServletInitializer {

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

  public static void main(String[] args) {
    SpringApplication.run(XXXWebApplication.class, args);
  }
}

下面是pom文件

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <spring-data-mock.version>1.1.4</spring-data-mock.version>
    <testng.version>6.9.6</testng.version>
    <hamcrest.version>1.3</hamcrest.version>
    <zxcvbn.version>1.2.3</zxcvbn.version>
</properties>

<dependencies>

    <!-- spring-boot -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </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-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-mail</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <!-- webjars -->
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>bootstrap</artifactId>
        <version>4.0.0-alpha.6</version>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>jquery</artifactId>
        <version>3.2.1</version>
    </dependency>

    <!-- database -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>

    <!-- commons -->
    <dependency>
        <groupId>org.codehaus.janino</groupId>
        <artifactId>janino</artifactId>
        <version>2.7.8</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.7</version>
    </dependency>

    <!-- Password complexity library -->
    <dependency>
        <groupId>com.nulab-inc</groupId>
        <artifactId>zxcvbn</artifactId>
        <version>${zxcvbn.version}</version>
    </dependency>

    <!-- test -->
    <dependency>
        <groupId>com.mmnaseri.utils</groupId>
        <artifactId>spring-data-mock</artifactId>
        <version>${spring-data-mock.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>${testng.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>${hamcrest.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/libs-milestone</url>
    </repository>
</repositories>

最佳, ģ

1 个答案:

答案 0 :(得分:0)

我终于找到了问题。为了解决这个问题,我必须注释掉tomcat依赖的范围,如下所示。

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

我从以下帖子java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context

得到了回复

感谢您的帮助。