洋芋1231 2023-04-07 16:47 采纳率: 100%
浏览 106
已结题

springboot启动报错 [main] ERROR org.springframework.boot.SpringApplication - Application run failed

springboot启动报错,帮忙看看啥子原因

18:46:30.606 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.NoSuchMethodError: org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent.getBootstrapContext()Lorg/springframework/boot/ConfigurableBootstrapContext;
    at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:101)
    at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:87)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:80)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:345)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at com.example.dubboapitestdemo.DubboapitestdemoApplication.main(DubboapitestdemoApplication.java:11)

Process finished with exit code 1


问题补充:
pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>dubboapitestdemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>dubboapitestdemo</name>
    <description>dubboapitestdemo</description>
    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <spring-boot.version>2.6.13</spring-boot.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.alibaba.boot</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>0.2.0</version>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.5</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>2.0.17</version>
        </dependency>

    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring-boot.version}</version>
                <configuration>
                    <mainClass>com.example.dubboapitestdemo.DubboapitestdemoApplication</mainClass>
                    <skip>true</skip>
                </configuration>
                <executions>
                    <execution>
                        <id>repackage</id>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>


启动类

package com.example.dubboapitestdemo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DubboapitestdemoApplication {


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

}

resources下添加了dubbo.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">

    <dubbo:application name="dubboapitestdemo" />
    <dubbo:registry  protocol="zookeeper"  address="127.0.0.1:2181" check="false" timeout="10000"/>
    <dubbo:protocol name="dubbo" port="20880" />
    <dubbo:reference id="helloService" interface="com.example.commonapi.service.HelloService" />
    <dubbo:reference id="studentService" interface="com.example.commonapi.service.StudentService" />

</beans>

使用背景:
对dubbo接口,想用testng实现接口自动化测试,新建的springboot,启动是正常的,后面引入了testng、dubbo的相关依赖后,再执行启动程序就报上面错了。测试类@test注解的方法是可以成功执行的。对java的话,熟悉基础部分,对框架不懂原理,是查了很多帖子依葫芦画瓢。希望描述清楚了,继续补充

测试类demo:

package com.example.dubboapitestdemo.testcase;

import com.example.commonapi.entity.Student;
import com.example.commonapi.service.StudentService;
import com.example.commonapi.utils.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.Date;

public class StudentServiceTest {

    @Autowired
    StudentService studentService;

    @Test
    public void insertStudentSuccessTest() {
        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext(new String[]{"dubbo.xml"});
        context.start();
        studentService = (StudentService) context.getBean("studentService");
        Student student = new Student();
        student.setSname("yoyo");
        student.setSsex("female");
        student.setSbirthday(new Date(20101013));
        student.setClazz("20150");
        ResultVO resultVO = studentService.insertStudent(student);
        System.out.println("~~~~~~~~~~~~~~~~~~~返回数据~~~~~~~~~~~~~~~~~~~~~~~~");
        System.out.println(resultVO);
        System.out.println(resultVO.getCode() + "" + resultVO.getMsg() + resultVO.getData());
        Assert.assertEquals(resultVO.getCode(), 1000);
    }

}

  • 写回答

5条回答 默认 最新

  • Mini厂程序员 2023-04-07 16:49
    关注

    看下引入的依赖

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

问题事件

  • 系统已结题 5月2日
  • 已采纳回答 4月24日
  • 修改了问题 4月7日
  • 修改了问题 4月7日
  • 展开全部

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题