Tag Archives: Microservices

[Solved] nacos Startup Error: Error creating bean with name ‘authFilterRegistration‘ defined in class path resource

Today, an error was suddenly reported when Nacos was started. The error information on the Nacos startup interface is as follows:

 Error creating bean with name 'authFilterRegistration' defined in class path resource
 [com/alibaba/nacos/core/auth/AuthConfig.class]: 
 Bean instantiation via factory method failed; 
 nested exception is org.springframework.beans.BeanInstantiationException:
 Failed to instantiate [org.springframework.boot.web.servlet.FilterRegistrationBean]:
 Factory method 'authFilterRegistration' threw exception;
 nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
 Error creating bean with name 'authFilter':
 Unsatisfied dependency expressed through field 'authManager';
 nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: 
 Error creating bean with name 'nacosAuthManager':
 Unsatisfied dependency expressed through field 'authenticationManager';
 nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
 Error creating bean with name 'nacosAuthConfig': 
 Unsatisfied dependency expressed through field 'userDetailsService';
 nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
 Error creating bean with name 'nacosUserDetailsServiceImpl':
 Unsatisfied dependency expressed through field 'userPersistService'; 
 nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
 Error creating bean with name 'externalUserPersistServiceImpl': 
 Unsatisfied dependency expressed through field 'persistService'; 
 nested exception is org.springframework.beans.factory.BeanCreationException: 
 Error creating bean with name 'externalStoragePersistServiceImpl': 
 Invocation of init method failed; nested exception is java.lang.RuntimeException:
 java.lang.RuntimeException: [db-load-error]load jdbc.properties error

Idea spooling error message:

[NACOS SocketTimeoutException httpGet] currentServerAddr:http://localhost:8848, err : connect timed out

Cause analysis: the project may not load Nacos related files correctly

Solution: delete the existing Nacos folder, decompress or download the Nacos compressed package again, and start startup.cmd. The problem is solved

If an error is reported, it may be that set mode = “” in the startup.cmd file is inappropriate

set BASE_DIR="%BASE_DIR:~0,-5%"

set CUSTOM_SEARCH_LOCATIONS=file:%BASE_DIR%/conf/

set MODE="cluster"
set FUNCTION_MODE="all"
set SERVER=nacos-server
set MODE_INDEX=-1
set FUNCTION_MODE_INDEX=-1
set SERVER_INDEX=-1
set EMBEDDED_STORAGE_INDEX=-1
set EMBEDDED_STORAGE=""

Solution: change set mode = "cluster" to set mode = "standalone".

[Solved] Openfegn Remote Call Error: java.lang.NullPointerException: null

Problem Description:

tip: version dependency is the worst problem


Solution:

Introduce spring cloud loadbalancer dependency

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-loadbalancer</artifactId>
    <version>3.0.3</version>
</dependency>

Due to the version problem, some must exclude ribbon dependencies from Nacos, otherwise the loadbalancer is invalid

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    <!--Client-side load balancing without Ribbon-->
    <exclusions>
        <exclusion>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Feign call Error: duplicate name [How to Solve]

 

Description:
The bean ‘personnel.FeignClientSpecification’, defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

Solution 1:
Applicati.yml configuration file is added to allow duplicate names

Solution 2:
Write together the contents of different feign interfaces called by the same microservice


Write the contents of the two interfaces together

es Failed to introspect Class [org.elasticsearch.client.RestHighLevelClient] from ClassLoader

This is usually a configuration error – it means that the code you use refers to a class, but the class itself is not in the classpath. In this case, this may also be a dependency management error in the relevant elasticsearch POMS itself, because it should contain the required classes

        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>7.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-client</artifactId>
            <version>7.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>7.6.2</version>
        </dependency>

Complete dependency, OK
(pay attention to switching to your version number)
maybe your mood is broken at the moment. Don’t worry. I believe it will bring you good luck _

elasticsearch NoClassDefFoundError error creating RestHighLevelClient bean

NoClassDefFoundError is usually a configuration error – which means that the code you use refers to a class, but the class itself is not in the classpath. In this case, this may also be a dependency management error in the relevant elasticsearch POMS itself, because it should contain the required classes

        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>7.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-client</artifactId>
            <version>7.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>7.6.2</version>
        </dependency>

Complete dependency, OK
(pay attention to switching to your own version)
maybe your mood is broken at the moment. Don’t worry. I believe it will bring you good luck _

How to Solve “Error db.num is null” when starting Nacos

Nacos startup is divided into stand-alone or cluster. When you start in cluster mode but do not configure the data source that the cluster depends on, the error db.num is null will be reported

Solution

The operation of this paper is based on Windows environment, similar to Linux

Mode 1: single machine mode startup

startup.cmd -m standalone

Start as shown in the figure below:

standalone: independent
at this time, Nacos starts in stand-alone mode

Mode 2: start in cluster mode and configure the data source

Use the conf/nacos-mysql.sql file to initialize the database, and modify the conf/application.properties file to add MySQL support

spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://localhost:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=1234

All the above configurations exist in the original configuration. You only need to modify the parameter value
after the modification is successful, start Nacos

startup.bat

Error creating bean with name ‘servletEndpointRegistrar‘ defined in class path resource

The errors encountered in writing as service items today are shown below. I only know that the creation of error creating bean with name ‘servletendpointregistrar’ defined in class path resource failed. I also found some solutions on the Internet. The most common solutions are that there is a lack of JDBC dependency, or that the database configuration file is wrong. I also compared the database, There is no lack of JDBC dependency, which shows that my database and dependency are correct. I compared other service services and found that more configuration files were introduced into the configuration file

[${project.name}] 2021-09-10 23:21:44,213 ERROR [localhost-startStop-1][Jdk14Logger.java:87] - Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration.class]: Unsatisfied dependency expressed through method 'servletEndpointRegistrar' parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'management.endpoints.web-org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties': Could not bind properties to 'WebEndpointProperties' : prefix=management.endpoints.web, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'management.endpoints.web.exposure' to org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties$Exposure
[${project.name}] 2021-09-10 23:21:44,240 WARN [main][Jdk14Logger.java:87] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
[${project.name}] 2021-09-10 23:21:44,241 INFO [main][DubboGenericServiceFactory.java:159] - The Dubbo GenericService ReferenceBeans are destroying...
[${project.name}] 2021-09-10 23:21:44,245 INFO [main][Jdk14Logger.java:87] - class org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor was destroying!

My Nacos profile is

#HTTP format configuration spring:
http:
  encoding:
    charset: UTF‐8
    force: true
    enabled: true
  messages:
    encoding: UTF‐8
#tomcat header information (user ip and access protocol) and access path configuration
server:
  tomcat:
    remote_ip_header: x‐forwarded‐for
    protocol_header: x‐forwarded‐proto
  servlet:
    context‐path: /lifly
  use‐forward‐headers: true

#Service monitoring and management configuration, operation and maintenance related
management:
  endpoints:
    web:
      exposure:
      include: refresh,health,info,env

This configuration file defines the user IP and access path, as well as some configuration files related to service monitoring, management and operation and maintenance. However, the remote call is not used in the service, but I introduced this configuration file. The reason for my error is this, so I recorded it
My bootstrap.yml configuration file is as follows:

server:
  port: 56050 
nacos:
  server:
    addr: 127.0.0.1:8848
spring:
  application:
    name: transaction-service
#  main:
#    allow-bean-definition-overriding: true # Spring Boot 2.1 
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848
#        server-addr: ${nacos.server.addr}
        namespace: 339eea59-f7f4-44d0-a3fa-9f1f85bd5b4f
#        cluster-name: COMMON_GROUP
      config:
        server-addr: 127.0.0.1:8848
#        server-addr: ${nacos.server.addr} 
        file-extension: yaml
        namespace: 339eea59-f7f4-44d0-a3fa-9f1f85bd5b4f  
        group: DEFAULT_GROUP 
        ext-config:
          -
            refresh: true
            data-id: spring-boot-http.yaml # spring boot http
            group: COMMON_GROUP 
#          -
#            refresh: true
#            data-id: spring-boot-starter-druid.yaml # spring boot starter druid
#            group: COMMON_GROUP 
#          -
#            refresh: true
#            data-id: spring-boot-mybatis-plus.yaml # spring boot mybatisplus
#            group: COMMON_GROUP 
#          - refresh: true
#            data-id: spring-boot-redis.yaml 
#            group: COMMON_GROUP 
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/huiminpay_transaction?useUnicode=true&useSSL=false
    #  url: jdbc:mysql://localhost:3306/huiminpay_merchant_service?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true&useUnicode=true
    username: root
    password: 1234
mybatis-plus:
  type-aliases-package: com.huiminpay.transaction.entity
  mapper-locations: classpath:/mapper/*.xml

dubbo:
  scan:
    # dubbo 
    base-packages: com.huiminpay
  protocol:
    # dubbo 协议
    name: dubbo
    port: 20893
  registry:
    address: nacos://127.0.0.1:8848
  application:
    qos:
      port: 22250 # dubbo qos
  consumer:
    check: false
    timeout: 3000
    retries: -1

logging:
  config: classpath:log4j2.xml

I commented out the import file and the project started. Record it again, and I hope it will be helpful to you. Comment out the following import file

 ext-config:
          -
            refresh: true
            data-id: spring-boot-http.yaml # spring boot http set
            group: COMMON_GROUP 

[Solved] hytrix service degraded bean cannot inject error

Solve the problem that the hytrix service degraded bean cannot inject errors

1. Error reporting prompt

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'deptConsumerController': Unsatisfied dependency expressed through field 'clientService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.xys.service.DeptClientService': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: No fallbackFactory instance of type class com.xys.service.DeptClientServiceFallbackFactory found for feign client SPRINGCLOUD-PROVIDER-DEPT
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1411) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:849) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at com.xys.Consumer.main(Consumer.java:14) [classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_261]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_261]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_261]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_261]
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.1.4.RELEASE.jar:2.1.4.RELEASE]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.xys.service.DeptClientService': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: No fallbackFactory instance of type class com.xys.service.DeptClientServiceFallbackFactory found for feign client SPRINGCLOUD-PROVIDER-DEPT
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:178) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:101) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1674) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getObjectForBeanInstance(AbstractAutowireCapableBeanFactory.java:1249) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:257) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1470) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1427) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1210) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1167) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:593) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	... 24 common frames omitted
Caused by: java.lang.IllegalStateException: No fallbackFactory instance of type class com.xys.service.DeptClientServiceFallbackFactory found for feign client SPRINGCLOUD-PROVIDER-DEPT
	at org.springframework.cloud.openfeign.HystrixTargeter.getFromContext(HystrixTargeter.java:79) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.springframework.cloud.openfeign.HystrixTargeter.targetWithFallbackFactory(HystrixTargeter.java:61) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.springframework.cloud.openfeign.HystrixTargeter.target(HystrixTargeter.java:51) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.springframework.cloud.openfeign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:238) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:267) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:247) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:171) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	... 35 common frames omitted

2. Solution

Add an annotation to your degraded entity class so that it can be scanned

@Component
public class DeptClientServiceFallbackFactory implements FallbackFactory {
    @Override
    public Object create(Throwable throwable) {
        return new DeptClientService() {
            @Override
            public Dept queryById(Long id) {
                return new Dept()
                        .setDept_no(id)
                        .setDept_name("id=>"+id+"There is no corresponding information, the client has provided information about the downgrade and this service is now closed")
                        .setDb_source("No data");
            }

            @Override
            public List<Dept> queryAll() {
                return null;
            }

            @Override
            public boolean addDept(Dept dept) {
                return false;
            }
        };
    }
}