【问题标题】:Tomcat 7 start failed with srpingbootTomcat 7启动失败,春季启动
【发布时间】:2023-03-05 03:41:01
【问题描述】:

我尝试运行一个 spring-boot 应用程序(Tomcat 7、Jdk 1.8、maven)(它不是嵌入式 tomcat),但遇到了几个问题,例如:

 Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.AbstractMethodError: org.springframework.boot.context.config.ConfigFileApplicationListener.supportsSourceType(Ljava/lang/Class;)Z
    at org.springframework.context.event.GenericApplicationListenerAdapter.supportsSourceType(GenericApplicationListenerAdapter.java:79)
    at org.springframework.context.event.AbstractApplicationEventMulticaster.supportsEvent(AbstractApplicationEventMulticaster.java:289)
    at org.springframework.context.event.AbstractApplicationEventMulticaster.retrieveApplicationListeners(AbstractApplicationEventMulticaster.java:221)
    at org.springframework.context.event.AbstractApplicationEventMulticaster.getApplicationListeners(AbstractApplicationEventMulticaster.java:192)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:75)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:347)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:306)
    at ep.OWebApplicationInitializer.main(OWebApplicationInitializer.java:14)

怎么了? 我的主要课程:

@SpringBootApplication
public class OWebApplicationInitializer extends SpringBootServletInitializer  {
    public static void main(String[] args) {
        new SpringApplication(OWebApplicationInitializer.class).run(args);
    }

}

我的 pom 就是这样:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </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-test</artifactId>
            <scope>test</scope>
        </dependency>

有人知道这个问题吗?

【问题讨论】:

  • AbstractMethodError 通常意味着您正在(在服务器中)针对与编译时使用的库版本不同的库版本执行。在用于编译方法的库中是具体的,而在服务器的库中是抽象的。
  • 为什么要排除tomcat依赖?你自己加的吗?
  • 是的,我添加了我的 .. Tomcat 7(我的项目是必需的).. 但我使用了最新版本的 springboot .. 可能是问题的原因? org.springframework.bootspring-boot-starter-parent2.1.4.RELEASE

标签: spring spring-boot tomcat7


【解决方案1】:

您在类路径上的依赖项版本不匹配。

<parent>
<groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

并使用 Tomcat 8。

【讨论】:

【解决方案2】:

你可以覆盖 SpringBootServletInitializer 的配置:

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    return builder.sources(OWebApplicationInitializer.class);
}

【讨论】:

  • 他为什么要这么做?你的回答如何解决问题?
猜你喜欢
  • 2016-12-13
  • 2021-06-10
  • 2014-06-26
  • 2018-10-28
  • 2018-10-29
  • 2021-07-14
  • 1970-01-01
  • 2018-10-22
相关资源
最近更新 更多