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

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 xy坐标转化为经纬度坐标
  • ¥15 一般三角模糊数的上界值和下届值取中值的多少比较合理?
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥20 Hbase启动失败,无法启动HMaster
  • ¥15 sqpingboot在父模块已经引入了mybatisplus 在子组件不写版本号还是报错
  • ¥20 Lumerical FDTD solutions 中模型的相对阻抗,有效介电常数和有效磁导率的实部和虚部的数据如何获得?
  • ¥100 sql reporting service 远程smtp服务器配置支持
  • ¥15 ppyoloe_r带角度目标检测,loss_cls没法收敛
  • ¥15 淘宝交易指数如何解读,其关联的数据指标是什么