【问题标题】:Spring boot application staring failed in IntelliJIntelliJ 中的 Spring Boot 应用程序启动失败
【发布时间】:2019-09-20 08:20:16
【问题描述】:

我以前有 spring boot 应用程序,以前我习惯在 eclipse 中工作,最近切换到 IntelliJ,在 IntelliJ 应用程序中没有盯着看,这里我在启动时共享日志

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.0.RELEASE)

2019-09-20 13:34:56.609  INFO 30977 --- [  restartedMain] com.kn.Application                       : Starting Application on Dhanu-MAC.local with PID 30977 (/Applications/Data/RT/20190815_source_prod/2_etn_backend/target/classes started by dhanu in /Applications/Data/RT/20190815_source_prod/2_etn_backend)
2019-09-20 13:34:56.621  INFO 30977 --- [  restartedMain] com.kn.Application                       : The following profiles are active: dev
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/Users/dhanu/.m2/repository/org/codehaus/groovy/groovy/2.4.13/groovy-2.4.13.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2019-09-20 13:34:57.029  INFO 30977 --- [  restartedMain] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@5083ace5: startup date [Fri Sep 20 13:34:57 IST 2019]; root of context hierarchy
2019-09-20 13:35:04.145  INFO 30977 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/api]    : Initializing Spring embedded WebApplicationContext
2019-09-20 13:35:04.146  INFO 30977 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 7117 ms
2019-09-20 13:35:04.798  INFO 30977 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-09-20 13:35:04.799  INFO 30977 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2019-09-20 13:35:04.801  INFO 30977 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'corsFilter' to: [/*]
2019-09-20 13:35:04.803  INFO 30977 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2019-09-20 13:35:05.107  INFO 30977 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2019-09-20 13:35:05.111  WARN 30977 --- [  restartedMain] com.zaxxer.hikari.util.DriverDataSource  : Registered driver with driverClassName=oracle.jdbc.driver.OracleDriver was not found, trying direct instantiation.
2019-09-20 13:35:06.701  INFO 30977 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2019-09-20 13:35:07.535  INFO 30977 --- [  restartedMain] liquibase.database.core.OracleDatabase   : Could not set remarks reporting on OracleDatabase: com.zaxxer.hikari.pool.HikariProxyConnection.setRemarksReporting(boolean)
2019-09-20 13:35:13.940  INFO 30977 --- [  restartedMain] l.lockservice.StandardLockService        : Successfully released change log lock
2019-09-20 13:35:14.303  INFO 30977 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2019-09-20 13:35:18.144  INFO 30977 --- [  restartedMain] o.h.h.i.QueryTranslatorFactoryInitiator  : HHH000397: Using ASTQueryTranslatorFactory
2019-09-20 13:35:18.282  INFO 30977 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-09-20 13:35:20.040  WARN 30977 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jwtTokenProvider' defined in file [/Applications/Data/RT/20190815_source_prod/2_etn_backend/target/classes/com/kn/config/JwtTokenProvider.class]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlElement
2019-09-20 13:35:20.041  INFO 30977 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2019-09-20 13:35:20.045  INFO 30977 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2019-09-20 13:35:20.125  INFO 30977 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
2019-09-20 13:35:20.131  INFO 30977 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]

Process finished with exit code 0

正如我在日志中看到的,它与 DB 成功连接,但 tomcat 没有任何原因就停止了

我在这里卡了很长时间,有人可以帮忙吗?

【问题讨论】:

  • 在日志中:“在上下文初始化期间遇到异常 - 取消刷新尝试:org.springframework.beans.factory.BeanCreationException:在文件 [/Applications/Data/ RT/20190815_source_prod/2_etn_backend/target/classes/com/kn/config/JwtTokenProvider.class]:bean 实例化失败;嵌套异常是 java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlElement"
  • 我该怎么办?
  • 我的代码库中有那个 java 文件
  • 你用的是什么java版本?

标签: java spring spring-boot intellij-idea


【解决方案1】:

嵌套异常是java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlElement

问题在这里得到解答:How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException in Java 9

简而言之:随着 Java 9 的发布,所需的依赖关系已从 JDK 中删除。如果您使用 Java 8 JDK 启动应用程序,则会提供依赖关系并且您的应用程序可以工作。如果您使用 Java 9 JDK 或更高版本启动应用程序,则依赖项将不再存在并且无法启动。

修复它的正确解决方案是将所需的依赖项添加到您的项目中:

dependencies {
    // JAX-B dependencies for JDK 9+
    implementation "javax.xml.bind:jaxb-api:2.2.11"
    implementation "com.sun.xml.bind:jaxb-core:2.2.11"
    implementation "com.sun.xml.bind:jaxb-impl:2.2.11"
    implementation "javax.activation:activation:1.1.1"
}

Maven 依赖项

<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.2.11</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core -->
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-core</artifactId>
            <version>2.2.11</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl -->
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.2.11</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/javax.activation/activation -->
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1.1</version>
        </dependency>

【讨论】:

  • 补充一点,在 Java 9 中,该模块已被弃用以移除 (docs.oracle.com/javase/9/docs/api/java.xml.bind-summary.html),并在 Java 11 中被完全移除。我想我们可以使用标志 --add-modules=java。 xml.bind 可以在 In Java 9 和 Java 10 中使用来解析。但理想的方法是添加您提到的依赖项
  • 你是对的,这也在链接的答案中有所描述。但这不是一个未来证明的解决方案,这就是我省略它的原因。
  • 我使用的是maven,所以我在maven中添加了提到的依赖项,令人惊讶的是它可以工作,谢谢@Simulant
猜你喜欢
  • 2017-05-12
  • 2019-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-06
  • 1970-01-01
  • 2019-09-07
  • 1970-01-01
相关资源
最近更新 更多