Tag Archives: java

The Java class generated by protocol reports an error: cannot access

The Java class generated by protocol reports an error:

The generated template class reported an error. It was said on the Internet that the version was wrong, but I was sure that the version used was correct. Later, it was checked that a proto was introduced into the command_Path causes the generated template class to report an error

Error command:

protoc --proto_path=D:\000\hadoop-2.7.2-src\hadoop-yarn-project\hadoop-yarn\hadoop-yarn-api\src\main\proto\ --proto_path=D:\000\hadoop-2.7.2-src\hadoop-common-project\hadoop-common\src\main\proto\ --proto_path=.\ --java_out=.\ .\*.proto

Change to the following command:

protoc --proto_path=D:\000\hadoop-2.7.2-src\hadoop-common-project\hadoop-common\src\main\proto\  --proto_path=.\ --java_out=.\ .\*.proto

One less — proto_Path, and then the problem is solved

How to Solve Junit Unit Test Error: “No runnable methods“

Abnormal

The errors reported by JUnit unit test are as follows:

java.lang.Exception: No runnable methods

	at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:191)
	at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:128)
	at org.junit.runners.ParentRunner.validate(ParentRunner.java:416)
	at org.junit.runners.ParentRunner.<init>(ParentRunner.java:84)
	at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
	at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
	at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
	at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
	at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:36)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:50)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:221)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)

error code

import org.junit.Test;

public class Test01 {

    @Test
    public void test(){
        System.out.println("hello world");
    }
}

reason

There is no problem with the code @ test annotation is placed on the method, and the @test annotation is also from the package org.junit.Test

Simulate the environment where the problem code occurs: Maven project, with a main/Java/test01.Java and test/Java/test01.Java class

main/java/Test01.java

import org.junit.Test;

public class Test01 {
    @Test
    public void test01() {
        System.out.println("hello world - main/java/Test01.java");
    }
}

test/java/Test01.java

public class Test01 {
    public static void main(String[] args) {
        System.out.println("hello world - test/java/Test01.java");
    }
}

To solve the above problems, the following conditions must be met:

1.The same path. It means that the path of the class must be at the same level. If the test/java/Test01.javaand mian/java/Test01.javais the same level, the test/java/Test01.javaand mian/java/hello/Test01.javais not the same level , and there will be no conflict.
2.Same class name. Refer to the same class name in the same path as test/java/Test01.javathe main/java/Test01.javasame path and is both the name of the same class, test/java/Test02.javawith the main/java/Test01.javaconflict although the same path but different class name, it will not happen.
3.Use @Testcomments or not. In the case where the path and class name are the same, if main/java/Test01.javathere is an @Testannotated method in it, and test/java/Test01.javathere must be no @Testannotated method in it, this conflict will occur. If there is an @Testannotated method and the method name is different, it will be reported to use Junit Unit test error “No tests found matching Method test01(Test01) from ClassRequest@5387f9e0” .

After the above conditions are met, the above error will be reported by executing the test method with @test annotation under main/Java .

Solution:

Make their class paths different.

Make their class names different

Under test/Java, there must be methods using @test annotations

In short, it is recommended not to write test methods with @test comments under main/Java, let alone conflict them.

[Solved] Gunicorn timeout error: worker timeout

Gunicorn timeout error: worker timeout

I. Problem Description:

One morning, the developer suddenly reported a failure and the container restarted inexplicably. After checking the business container log, the worker timeout field was found

II. Analysis of error reporting reasons:

It can be seen from the error message that the worker process of gunicorn timed out, causing the process to exit and restart. Check the official website. The official website explains that the default timeout of gunicorn is 30s. If it exceeds 30s, the worker process will be killed and restarted.

III Solution:

Add: -- timeout 600 to gunicorn’s startup command to set the timeout to 600 seconds– Graceful timeout 600 indicates that the graceful timeout is 600 seconds

After the setting is completed, it is verified through kustomize inspection and re-distribution. It is found that the problem does not occur in the follow-up

[Solved] spring boot integrated PageHelper Error

The error reporting information is as follows:

 Error creating bean with name 

'com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration'

Description:

The dependencies of some of the beans in the application context form a cycle:

┌──->──┐
|  com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration
└──<-──┘

└──<-──┘

The spring boot version is 2.6.1

<parent>
   <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-parent</artifactId>
     <version>2.6.1</version>
   <relativePath/> <!-- lookup parent from repository -->
</parent>

The page helper version is 1.2.3

<!-- pageHelper -->
<dependency>
   <groupId>com.github.pagehelper</groupId>
   <artifactId>pagehelper-spring-boot-starter</artifactId>
   <version>1.2.3</version>
</dependency>

After verification by many parties, it is found that the error is due to the conflict between the springboot version and the PageHelper version.

Solution:

    1. reduce the springboot version, such as 2.5 3 (the PageHelper version remains unchanged from 1.2.3)
<parent>
   <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-parent</artifactId>
     <version>2.5.3</version>
   <relativePath/> <!-- lookup parent from repository -->
</parent>

Increase the version of PageHelper, such as 1.4 1 (the springboot version remains unchanged from 2.6.1)

<!-- pageHelper -->
<dependency>
   <groupId>com.github.pagehelper</groupId>
   <artifactId>pagehelper-spring-boot-starter</artifactId>
   <version>1.4.1</version>
</dependency>

I hope my solution will help you a little. Good luck!!!

How to Solve Springboot configurate environment file Error

preface

When configuring multiple environment files for springboot, you need to configure multiple YML files. The configuration before version 2.4 is as follows:

spring: 
  profiles:
    active: dev

But if SpringBoot’s version 2.4 later, it’s a reward.

org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property ‘spring.profiles.active[0]’ imported from location ‘class path resource [application-work.yml]’ is invalid in a profile specific resource [origin: class path resource [application-work.yml] - 9:7]

 

Solution:

General layout changes as follows:

spring:
  config:
    activate:
       on-profile:
          - dev

Of course, it can also be solved by returning the spring boot version to before 2.4

Spring cloud remote connect Nacos error [How to Solve]


Problem description

Spring cloud Alibaba micro service architecture is used, and Nacos is used in the service discovery and configuration center

At the beginning, Nacos was started locally, and everything was normal,

After Nacos is migrated to the cloud, change the Nacos address in the configuration file

The gateway service reports an error java.net.connectexception: no available server, because it is always connected to localhost:8848 .

The console outputs the following screenshot:

Cause location

Because the parent POM dependency is imported:

spring-cloud-starter-Alibaba-Nacos-config and spring-cloud-starter-Alibaba-Nacos-discovery

In local development, items such as testing, registration and discovery are configured in application.yml, the central configuration file bootstrap.properties is not created

Springboot automation configuration defaults to localhost:8848 , so there is no problem with the local environment.

Solution:

Remove useless dependencies (if nacos-config is not used, remove spring-cloud-starter-alibaba-nacos-config dependencies)

[Solved] Springboot connect MySQL error: errorcode 0, state 08s01

preface

For a project that has not been maintained for a long time, you need to check some data. Re run the project and find create connection sqlexception, and the specific error messages are errorcode 0, state 08s01.

Springboot version 2.5, MySQL 8.0

Error reporting details

2021-12-18 22:47:14.834 ERROR 20196 --- [reate-940563698] com.alibaba.druid.pool.DruidDataSource   : create connection SQLException, url: jdbc:mysql://localhost:3306/renrenfast?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai, errorCode 0, state 08S01

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
	at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:827)
	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:447)
	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:237)
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
	at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:156)
	at com.alibaba.druid.filter.FilterAdapter.connection_connect(FilterAdapter.java:786)
	at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150)
	at com.alibaba.druid.filter.stat.StatFilter.connection_connect(StatFilter.java:218)
	at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1572)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1636)
	at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2550)
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
	at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
	at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)
	at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)
	at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:340)
	at com.mysql.cj.protocol.a.NativeAuthenticationProvider.negotiateSSLConnection(NativeAuthenticationProvider.java:777)
	at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:486)
	at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:202)
	at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1348)
	at com.mysql.cj.NativeSession.connect(NativeSession.java:163)
	at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:947)
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:817)
	... 11 common frames omitted
Caused by: javax.net.ssl.SSLHandshakeException: Invalid Alert message: no sufficient data
	at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:131)
	at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117)
	at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:336)
	at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:292)
	at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:283)
	at java.base/sun.security.ssl.Alert$AlertMessage.<init>(Alert.java:196)
	at java.base/sun.security.ssl.Alert$AlertConsumer.consume(Alert.java:236)
	at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:185)
	at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:171)
	at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1408)
	at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1314)
	at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:440)
	at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:411)
	at com.mysql.cj.protocol.ExportControlled.performTlsHandshake(ExportControlled.java:316)
	at com.mysql.cj.protocol.StandardSocketFactory.performTlsHandshake(StandardSocketFactory.java:188)
	at com.mysql.cj.protocol.a.NativeSocketConnection.performTlsHandshake(NativeSocketConnection.java:99)
	at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:331)
	... 18 common frames omitted

Configuration details

spring:
    datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        druid:
            driver-class-name: com.mysql.cj.jdbc.Driver
            url: jdbc:mysql://localhost:3306/xxx?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai

Solution:

Just add &useSSL=false

spring:
    datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        druid:
            driver-class-name: com.mysql.cj.jdbc.Driver
            url: jdbc:mysql://localhost:3306/xxx?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false

Effect detection

It’s really running! It seems that

[Solved] IDEA plug-in jrbel hot deployment cannot be started error

The idea plug-in jrbel hot deployment fails to start, and an error is reported: jrebel JVMTI [fat] a fatal error occurred while processing the base Java classes The JVM has been shut down (1).

due to JDK charges, openjdk has been replaced. Recently, it cannot be used due to hot deployment. The reason for the error is the openjdk problem. Maybe the openjdk file has been rewritten. Just replace it with another JDK.