nacos+seata配置启动总是报错,找不到解决方法

maven目录:

idea工具自动添加的包
按官网自动生产了sql数据,nacos和seata服务端均配置和启动正常。
但stock和order无法启动,pom文件:

 <artifactId>stock-service</artifactId>

<parent>

<artifactId>nacos-seata</artifactId>

<groupId>org.example</groupId>

<version>1.0-SNAPSHOT</version>

</parent>

<dependencies>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

</dependency>

<dependency>

<groupId>com.alibaba.cloud</groupId>

<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>

</dependency>

<dependency>

<groupId>com.alibaba.cloud</groupId>

<artifactId>spring-cloud-starter-alibaba-seata</artifactId>

</dependency>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-test</artifactId>

<scope>test</scope>

<exclusions>

<exclusion>

<groupId>org.junit.vintage</groupId>

<artifactId>junit-vintage-engine</artifactId>

</exclusion>

</exclusions>

</dependency>

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-openfeign</artifactId>

</dependency>

<dependency>

<groupId>org.projectlombok</groupId>

<artifactId>lombok</artifactId>

</dependency>

<dependency>

<groupId>org.example</groupId>

<artifactId>mysql-config</artifactId>

<version>1.0-SNAPSHOT</version>

</dependency>

</dependencies>

application.yml:

server:

port: 9000

spring:

application:

name: stock-service

# Nacos帮助文档: https://nacos.io/zh-cn/docs/concepts.html

# Nacos认证信息

cloud:

nacos:

discovery:

username: nacos

password: nacos

# Nacos 服务发现与注册配置,其中子属性 server-addr 指定 Nacos 服务器主机和端口

server-addr: 127.0.0.1:8848

group: SEATA_GROUP

# 注册到 nacos 的指定 namespace,默认为 public

alibaba:

seata:

tx-service-group: my_test_tx_group

datasource:

druid:

url: jdbc:mysql://localhost:3306/seata_stock?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC

driverClassName: com.mysql.cj.jdbc.Driver

username: root

password: 123456

# seata 服务分组,要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应

logging:

level:

io:

seata: debug

# 数据源配置

seata:

service:

vgroupMapping: my_test_tx_group

registry:

type: nacos

nacos:

application: seata-server

server-addr: 127.0.0.1:8848

group : "SEATA_GROUP"

namespace: "seata_namespace_id"

username: "nacos"

password: "nacos"

config:

type: nacos

nacos:

server-addr: 127.0.0.1:8848

group: "SEATA_GROUP"

namespace: "seata_namespace_id"

username: "nacos"

password: "nacos"

application-id: ${spring.application.name}

启动文件:

@EnableFeignClients

@EnableDiscoveryClient

@SpringBootApplication(scanBasePackages = {"com.example"}, exclude = DataSourceAutoConfiguration.class)

public class StockServiceApplication {

public static void main(String[] args) {

SpringApplication.run(StockServiceApplication.class, args);

}

}

mysql-config配置:

@Configuration

public class config {

/**

* @param sqlSessionFactory SqlSessionFactory

* @return SqlSessionTemplate

*/

@Bean

public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {

return new SqlSessionTemplate(sqlSessionFactory);

}

/**

* 从配置文件获取属性构造datasource,注意前缀,这里用的是druid,根据自己情况配置,

* 原生datasource前缀取"spring.datasource"

*

* @return

*/

@Bean

@ConfigurationProperties(prefix = "spring.datasource.druid")

public DataSource druidDataSource() {

DruidDataSource druidDataSource = new DruidDataSource();

return druidDataSource;

}

/**

* 构造datasource代理对象,替换原来的datasource

*

* @param druidDataSource

* @return

*/

@Primary

@Bean("dataSource")

public DataSourceProxy dataSourceProxy(DataSource druidDataSource) {

return new DataSourceProxy(druidDataSource);

}

@Bean(name = "sqlSessionFactory")

public SqlSessionFactory sqlSessionFactoryBean(DataSourceProxy dataSourceProxy) throws Exception {

MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();

bean.setDataSource(dataSourceProxy);

ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();

// bean.setConfigLocation(resolver.getResource("classpath:mybatis-config.xml"));

bean.setMapperLocations(resolver.getResources("classpath*:mybatis/**/*-mapper.xml"));

SqlSessionFactory factory = null;

try {

factory = bean.getObject();

} catch (Exception e) {

throw new RuntimeException(e);

}

return factory;

}

/**

* MP 自带分页插件

*

* @return

*/

@Bean

public PaginationInterceptor paginationInterceptor() {

PaginationInterceptor page = new PaginationInterceptor();

page.setDialectType("mysql");

return page;

}

}

父文件pom:

<groupId>org.example</groupId>

<artifactId>nacos-seata</artifactId>

<packaging>pom</packaging>

<version>1.0-SNAPSHOT</version>

<modules>

<module>mysql-config</module>

<module>order-service</module>

<module>stock-service</module>

</modules>

<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.3.7.RELEASE</spring-boot.version>

<spring-cloud-alibaba.version>2.2.2.RELEASE</spring-cloud-alibaba.version>

</properties>

<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>

<dependency>

<groupId>com.alibaba.cloud</groupId>

<artifactId>spring-cloud-alibaba-dependencies</artifactId>

<version>${spring-cloud-alibaba.version}</version>

<type>pom</type>

<scope>import</scope>

</dependency>

<dependency>

<groupId>com.alibaba</groupId>

<artifactId>druid-spring-boot-starter</artifactId>

<version>1.1.10</version>

</dependency>

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

<version>8.0.27</version>

</dependency>

<dependency>

<groupId>com.baomidou</groupId>

<artifactId>mybatis-plus-boot-starter</artifactId>

<version>3.1.1</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-openfeign -->

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-openfeign</artifactId>

<version>2.2.10.RELEASE</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->

<dependency>

<groupId>org.projectlombok</groupId>

<artifactId>lombok</artifactId>

<version>1.18.22</version>

<scope>provided</scope>

</dependency>

</dependencies>

</dependencyManagement>

报错如下:

java.lang.IllegalStateException: Error processing condition on io.seata.spring.boot.autoconfigure.SeataAutoConfiguration.failureHandler

at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60) ~[spring-boot-autoconfigure-2.3.7.RELEASE.jar:2.3.7.RELEASE]

at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:184) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:144) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:120) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:280) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:96) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:707) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:533) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE]

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE]

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE]

at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE]

at com.example.stockservice.StockServiceApplication.main(StockServiceApplication.java:13) [classes/:na]

Caused by: java.lang.IllegalStateException: Failed to introspect Class [io.seata.spring.boot.autoconfigure.SeataAutoConfiguration] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]

at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481) ~[spring-core-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:358) ~[spring-core-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:414) ~[spring-core-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.lambda$getTypeForFactoryMethod$2(AbstractAutowireCapableBeanFactory.java:742) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[na:1.8.0_291]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:741) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:680) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:648) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1614) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:523) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:495) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.boot.autoconfigure.condition.OnBeanCondition.collectBeanNamesForType(OnBeanCondition.java:238) ~[spring-boot-autoconfigure-2.3.7.RELEASE.jar:2.3.7.RELEASE]

at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:231) ~[spring-boot-autoconfigure-2.3.7.RELEASE.jar:2.3.7.RELEASE]

at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:221) ~[spring-boot-autoconfigure-2.3.7.RELEASE.jar:2.3.7.RELEASE]

at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:169) ~[spring-boot-autoconfigure-2.3.7.RELEASE.jar:2.3.7.RELEASE]

at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:144) ~[spring-boot-autoconfigure-2.3.7.RELEASE.jar:2.3.7.RELEASE]

at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47) ~[spring-boot-autoconfigure-2.3.7.RELEASE.jar:2.3.7.RELEASE]

... 18 common frames omitted

Caused by: java.lang.NoClassDefFoundError: io/seata/spring/annotation/datasource/SeataAutoDataSourceProxyCreator

at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_291]

at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_291]

at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_291]

at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.2.12.RELEASE.jar:5.2.12.RELEASE]

... 34 common frames omitted

Caused by: java.lang.ClassNotFoundException: io.seata.spring.annotation.datasource.SeataAutoDataSourceProxyCreator

at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_291]

at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[na:1.8.0_291]

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) ~[na:1.8.0_291]

at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[na:1.8.0_291]

... 38 common frames omitted

2021-12-20 20:44:06.476 WARN 3612 --- [ main] o.s.boot.SpringApplication : Unable to close ApplicationContext

java.lang.IllegalStateException: Failed to introspect Class [io.seata.spring.boot.autoconfigure.SeataAutoConfiguration] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]

at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481) ~[spring-core-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:358) ~[spring-core-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:414) ~[spring-core-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.lambda$getTypeForFactoryMethod$2(AbstractAutowireCapableBeanFactory.java:742) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[na:1.8.0_291]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:741) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:680) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:648) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1614) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:523) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:495) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:620) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:612) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1243) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]

at org.springframework.boot.SpringApplication.getExitCodeFromMappedException(SpringApplication.java:880) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE]

at org.springframework.boot.SpringApplication.getExitCodeFromException(SpringApplication.java:868) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE]

at org.springframework.boot.SpringApplication.handleExitCode(SpringApplication.java:855) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE]

at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:806) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:325) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE]

at com.example.stockservice.StockServiceApplication.main(StockServiceApplication.java:13) [classes/:na]

Caused by: java.lang.NoClassDefFoundError: io/seata/spring/annotation/datasource/SeataAutoDataSourceProxyCreator

at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_291]

at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_291]

at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_291]

at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.2.12.RELEASE.jar:5.2.12.RELEASE]

... 21 common frames omitted

Caused by: java.lang.ClassNotFoundException: io.seata.spring.annotation.datasource.SeataAutoDataSourceProxyCreator

at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_291]

at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[na:1.8.0_291]

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) ~[na:1.8.0_291]

at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[na:1.8.0_291]

... 25 common frames omitted

这个问题怎么解决呢?


回答:

Caused by: java.lang.ClassNotFoundException: io.seata.spring.annotation.datasource.SeataAutoDataSourceProxyCreator

这玩意怕是少了啥依赖吧,

<dependency>

        <groupId>com.alibaba.cloud</groupId>

<artifactId>spring-cloud-starter-alibaba-seata</artifactId>

<exclusions>

<exclusion>

<artifactId>seata-all</artifactId>

<groupId>io.seata</groupId>

</exclusion>

</exclusions>

</dependency>

<dependency>

<groupId>io.seata</groupId>

<artifactId>seata-spring-boot-starter</artifactId>

<version>${seata.version}</version>

</dependency>

<dependency>

<groupId>io.seata</groupId>

<artifactId>seata-all</artifactId>

<version>${seata.version}</version>

</dependency>

这是我本地的依赖

以上是 nacos+seata配置启动总是报错,找不到解决方法 的全部内容, 来源链接: utcz.com/p/944120.html

回到顶部