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);
}
}