【问题标题】:Spring Rest Application is not starting (NullPointerException)Spring Rest 应用程序未启动(NullPointerException)
【发布时间】:2020-04-22 23:56:35
【问题描述】:

这是 API 所在的存储库的链接:

https://github.com/moreiravictor/postAPI

控制台向我打印以下错误:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/ruivoo/.m2/repository/ch/qos/logback/logback-classic/1.1.3/logback-classic-1.1.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/ruivoo/.m2/repository/org/slf4j/slf4j-simple/1.7.7/slf4j-simple-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
Exception in thread "main" java.lang.NullPointerException
    at org.springframework.core.BridgeMethodResolver.findBridgedMethod(BridgeMethodResolver.java:64)
    at org.springframework.beans.GenericTypeAwarePropertyDescriptor.<init>(GenericTypeAwarePropertyDescriptor.java:70)
    at org.springframework.beans.CachedIntrospectionResults.buildGenericTypeAwarePropertyDescriptor(CachedIntrospectionResults.java:348)
    at org.springframework.beans.CachedIntrospectionResults.<init>(CachedIntrospectionResults.java:302)
    at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:189)
    at org.springframework.beans.BeanUtils.getPropertyDescriptors(BeanUtils.java:359)
    at org.springframework.boot.bind.PropertiesConfigurationFactory.getNames(PropertiesConfigurationFactory.java:263)
    at org.springframework.boot.bind.PropertiesConfigurationFactory.doBindPropertiesToTarget(PropertiesConfigurationFactory.java:252)
    at org.springframework.boot.bind.PropertiesConfigurationFactory.bindPropertiesToTarget(PropertiesConfigurationFactory.java:227)
    at org.springframework.boot.context.config.ConfigFileApplicationListener.bindToSpringApplication(ConfigFileApplicationListener.java:196)
    at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:147)
    at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:139)
    at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:127)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:151)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128)
    at org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:100)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:59)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:286)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:969)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:958)
    at br.com.espatodea.postAPI.App.main(App.java:9)

【问题讨论】:

  • "See http://www.slf4j.org/codes.html#multiple_bindings for an explanation"
  • 更正构建路径。现在只有 src 在构建路径中。从构建路径中删除 src 并将其更改为 src/main/java。做 Maven 清理和构建。
  • 两者都不起作用,错误保持不变

标签: java spring rest api model-view-controller


【解决方案1】:

存在 SLF4J 版本冲突,堆栈跟踪清楚地解释了这一点。第 4 行说:

SLF4J:请参阅 http://www.slf4j.org/codes.html#multiple_bindings 了解说明。

提供的解决方案之一是从 Lombok 中排除 SLF4J:

<exclusions>
  <exclusion> 
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
  </exclusion>
  <exclusion> 
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
  </exclusion>
</exclusions> 

但是,我看到其中一个依赖项是明确的 /org/slf4j/slf4j-simple/1.7.7,所以我会删除这个。

【讨论】:

  • 谢谢。它有效,但现在我有这个: org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155) 的线程“main”java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory 中的异常。 apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132) 在 org.apache.commons.logging.LogFactory.getLog(LogFactory.java:273) 在 org.springframework.boot.SpringApplication.( SpringApplication.java:162) 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:969) 在 org.springframework.boot.SpringApplication.run [...]
  • 非常感谢您的帮助,但我决定去 spring initializr 并创建一个具有正确依赖项的新项目,这样更容易。您的回答将我引向了正确的方向,但还有其他问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-10
  • 2020-01-16
相关资源
最近更新 更多