Error creating bean with name ‘configurationPropertiesBeans

created at 06-13-2022 views: 12

Spring access to Nacos got error

Error creating bean with name 'configurationPropertiesBeans'
  1. Add related dependencies

Note that the spring-cloud method is used to import here, and you need to pay attention to the compatibility of the two:

https://spring.io/projects/spring-cloud

At the same time, it should be noted that the bootstap file is not supported after the spring-cloud 2020.xxx version

<!--Service Discovery Dependency-->
<dependency>
  <groupId>com.alibaba.cloud</groupId>
  <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
  <version>2.2.5.RELEASE</version>
</dependency>
<!--Remote configuration problem-->
<dependency>
  <groupId>com.alibaba.cloud</groupId>
  <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
  <version>2.2.5.RELEASE</version>
</dependency>

1.Add a configuration file bootstrap.yml

spring:
   profiles:
     # default type
     active: dev
   application:
     name: xxxxxxxxx-${spring.profiles.active}
   cloud:
     nacos:
       discovery:
         # Specify the namespace of nacos
         namespace: ${spring.cloud.nacos.config.namespace}
       config:
         file-extension: yaml
         # nacos address
         server-addr: ${spring.cloud.nacos.server-addr}
         namespace: ${spring.cloud.nacos.discovery.namespace}
         extension-configs:
           # metrics config
           - dataId: global-config.yml
             group: GLOBAL_GROUP
             refresh: true
             # email config
           - dataId: mail-config.yml
             group: GLOBAL_GROUP
             refresh: true
# ${} This method takes the jvm parameter first, and then takes the internal definition of the file; take spring.profiles.active as an example;
# Note that the name must be the same as the configuration name on nacos; use this matching

2.Add configuration parameters

-Dspring.cloud.nacos.server-addr=http://xxxxxxxxxxxxxxxx
-DlogsDir=./xxxxxxxxxxxxxxxxxxxxx
-Dspring.cloud.nacos.config.namespace=xxxxx
-Dspring.profiles.active=xxxxx
  1. Start the program:

An error occurs

rg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationPropertiesBeans' defined in class path resource [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]

The final investigation is springboot and spring cloud version conflict, it is OK to downgrade from 2.6.3 to 2.2.5.RELEASE

Online service error:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration':

Reason investigation

Confirm missing class: org.apache.http.HttpRequestInterceptor

Belongs to the dependent jar package: httpcore;

Check dependencies: found set to test

<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpcore</artifactId>
  <version>4.4.13</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpclient</artifactId>
  <version>4.5.11</version>
  <scope>test</scope>
</dependency>

Enter the container to confirm:

Missing jar package for httpcore in packaged lib

Dependency removed test scope and repackaged to the cloud, no problem

summary

Introducing dependencies and adding test scope directly leads to the lack of these two dependent jar packages when packaging the project

created at:06-13-2022
edited at: 06-13-2022: