Category Archives: JAVA

[Solved] ApplicationContextException: Failed to start bean ‘documentationPluginsBootstrapper‘;

ApplicationContextException: Failed to start bean ‘documentationPluginsBootstrapper‘;

Spring boot reports the following errors:

org.springframework.context.applicationContextException: Failed to start bean ‘documentationPluginsBootstrapper’; nested exception is java. lang.NullPointerException

After testing for a long time, it is found that the reason for swagger2:

Version 3.0.0 was originally used:

<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>3.0.0</version>
</dependency>

It is said that:

Reason: This is because Springfox uses path matching based on AntPathMatcher, while Spring Boot 2.6.X uses PathPatternMatcher.
Solution: Configure in application.properties: spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER

After testing, no error was reported, but the search access http://localhost:8080/swagger-ui.html has 404

Final solution:

Switch the version of swagger2 and swaggerui to version 2.9.2

<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.9.2</version>
</dependency>

If it does not work like me, just add the following code in application.properties:

spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER

Problem solved!

[Solved] Springboot integrate swagger error: Failed to start bean ‘documentationPluginsBootstrapper‘

spring boot upgrade to 2.6.x+ version, I suddenly found the following error when integrating with swagger:

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException

Reason: because the path matching used by springfox is based on AntPathMatcher, and spring boot 2.6.X uses PathPatternMatcher, which can change the matching rules

Solution:
add the following configuration in the configuration file (application.yaml)

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

[Solved] Docker-maven-plugin Build Mirror Error: failed: Connection refused: connect

Docker-maven-plugin Build Mirror Error: failed: Connection refused: connect

[ERROR] Failed to execute goal com.spotify:dockerfile-maven-plugin:1.4.7:build (default) on project security-api: Could not build image: java.util.concurrent.ExecutionException: com.spotify.docker.client.sha
ded.javax.ws.rs.ProcessingException: com.spotify.docker.client.shaded.org.apache.http.conn.HttpHostConnectException: Connect to localhost:2375 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connect
ion refused: connect -> [Help 1]

 

Solution:

  1. Go to docker settings (Second mouse click on docker icon, click settings)
  2. Click on checkbox ‘Expose daemon on tcp://localhost:2375 without TLS’
  3. Apply & Restart
  4. Run again: mvn clean install

IDEA Error: ERROR 16720 —[ restartMain] o.a.coyote. http11.Http119Protocol: Failed to sta

Idea reports error: ERROR 16720 – [restartedmain] o.a.coyote http11.Http11NioProtocol : Failed to start end point associated with ProtocolHandler [“http-nio-80”]

1. Error 16720

idea version is IntelliJ idea 2018.3.6 x64

The error reporting codes of running items are as follows:


the detailed error reporting code of the third figure

Sun May 29 10:42:36 CST 2022 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun May 29 10:42:36 CST 2022 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun May 29 10:42:37 CST 2022 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun May 29 10:42:37 CST 2022 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun May 29 10:42:37 CST 2022 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun May 29 10:42:37 CST 2022 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun May 29 10:42:37 CST 2022 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun May 29 10:42:37 CST 2022 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun May 29 10:42:37 CST 2022 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun May 29 10:42:37 CST 2022 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

2. Error reporting causes and Solutions

1. cause

Port number 80 is occupied

2. solutions

1. change the port number and use the idle port number

the occupied port number here is 80, and the idle port number is 81

(1) Find the configuration file to write the port number

server:
  port: 80

(2) Change the port number to an idle and unoccupied port number

server:
  port: 81

 

[Solved] RedisTemplate increment Error: io.lettuce.core.RedisCommandExecutionException: ERR value is not an intege

Redistemplate uses increment to report an error: io.lettuce.core.RedisCommandExecutionException: ERR value is not an intege

Problem analysis

We can learn from spring’s documents that spring has two rare serialization strategies for redis. One is the JDKSerializationRedisSerialzer serialization of RedisTemplate application. The serialized value contains object information, version number, class information, etc. after this serialization, a string cannot be self incremented.

The other is the StringRedisSerializer adopted by the StringRedisTemplate. This strategy converts the string value into a byte array, so the values saved in redis can be operated.

Solution:

Replace RedisTemplate with String RedisTemplate

[Solved] Log Error: NAN OR INFINITY

Log Error: NAN OR INFINITY

An error is reported in the log today: infinity or Nan. After checking the code, it is found that float performs the division operation /0.

In integer int operations, the divisor cannot be 0. Otherwise, an exception will be reported directly. But what is it like in floating-point arithmetic?Let’s have a look.

1.infinity: infinite

Observe the results of the following outputs:

        double POSITIVE_INFINITY = 1.0/0.0;
		double NEGATIVE_INFINITY = -1.0/0.0;
		System.out.println(POSITIVE_INFINITY);
		System.out.println(NEGATIVE_INFINITY);
		float POSITIVE_INFINITY2 = 1.0f/0.0f;
		float NEGATIVE_INFINITY2 = -1.0f/0.0f;
		System.out.println(POSITIVE_INFINITY2);
		System.out.println(NEGATIVE_INFINITY2);

Output results:

Infinity
-infinity
infinity
-infinity

Take another look at the following examples and output results:

        //Infinite multiplication by 0 results in NAN
		System.out.println(Float.POSITIVE_INFINITY * 0); // output: NAN
		System.out.println(Float.NEGATIVE_INFINITY * 0); // output: NAN

		//Dividing infinity by 0, the result remains the same, or infinity
		System.out.println((Float.POSITIVE_INFINITY/0) == Float.POSITIVE_INFINITY); // output: true
		System.out.println((Float.NEGATIVE_INFINITY/0) == Float.NEGATIVE_INFINITY); // output: true
		
		//Infinite does all operations except multiplying by zero, and the result is still infinite
		System.out.println(Float.POSITIVE_INFINITY == (Float.POSITIVE_INFINITY + 10000)); // output: true
		System.out.println(Float.POSITIVE_INFINITY == (Float.POSITIVE_INFINITY - 10000)); // output: true
		System.out.println(Float.POSITIVE_INFINITY == (Float.POSITIVE_INFINITY * 10000)); // output: true
		System.out.println(Float.POSITIVE_INFINITY == (Float.POSITIVE_INFINITY/10000)); // output: true

To determine whether a floating-point number is infinite, you can use the isinfinite method:

System.out.println(Double.isInfinite(Float.POSITIVE_INFINITY)); // output: true

2.NAN

System.out.println(0.0d/0.0); //NaN

Nan means non numeric. It is not equal to any value, or even to itself. To judge whether a number is a Nan, use the IsNaN method:

System.out.println(Float.NaN == Float.NaN); // output: false
System.out.println(Double.isNaN(Float.NaN)); // output: true

https://blog.csdn.net/susu1083018911/article/details/124993209

How to Solve Error: Error parsing mapper XML

[Solved] Error parsing Mapper XML

Error parsing mapper xml
this error message is essentially a mapper XML error
failed resolve xxx XML, etc.
here we analyze some problems that will not become popular when writing, and that will cause errors when starting

1. ID conflict

The conflicts here are
resultmap

<resultMap type="com.newtouch.business.module.dto.T01agentComDTO" id="t01agentComMap">

<resultMap type="com.cpi.newtouch.business.module.dto.T01comDTO" id="t01agentComMap">

Specific SQL

<select id="findBy" >
<update id="findBy">

As long as two or more IDs are the same, an error will be reported. This usually happens because you don’t pay attention to copy and paste. You need to be careful!

2. Return type error

<resultMap type="com.newtouch.business.module.dto.T01agentComDTO" id="t01agentComMap">
<select id="findBy" resultType="t01agentComMap">

Like here, I returned the resultmap, but wrote the resulttype

Similarly, for example, if I return a string type, but I write a resultmap, I will also report an error

3. Not writing the full class name

<resultMap type="com.newtouch.business.module.dto.T01agentComDTO" id="t01agentComMap">

The resultmap, if I write it like this

<resultMap type="T01agentComDTO" id="t01agentComMap">

An error will be reported. Of course, if relevant settings are configured

[Solved] SpringCloud Compile Error: java: JPS incremental annotation processing is disabled. Compilation results on partial recompilation may be inaccurate.

Error:

SpringCloud Compile Error: java: JPS incremental annotation processing is disabled. Compilation results on partial recompilation may be inaccurate. Use build process “jps.track.ap.dependencies” VM flag to enable/disable incremental annotation processing environment.

 

Solution:
1.Add: -Djps.track.ap.dependencies=false

2. Clear the caches

[Solved] Springboot error: Could Not Found xxmapper

springboot error: could not found xxmapper

Error Messages:

Unsatisfied dependency expressed through field ‘baseMapper’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.xxxx.server.mapper.AdminMapper’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

 

 

Solution: Add mapper package scan to springboot startup class

@MapperScan("com.xxxx.server.mapper")

[Solved] JAVA Operate Database Error: You have an error in your SQL syntax; Dao layer SQL statement error

JAVA Operate Database Error: You have an error in your SQL syntax; Dao layer SQL statement error

Specific error reports are as follows:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?,?,?,?,?)' at line 1
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
	at com.mysql.jdbc.Util.getInstance(Util.java:408)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3978)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3914)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2491)
	at com.mysql.jdbc.StatementImpl.executeUpdateInternal(StatementImpl.java:1552)
	at com.mysql.jdbc.StatementImpl.executeLargeUpdate(StatementImpl.java:2607)
	at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1480)
	at cn.edu.wut.jwms.dao.TeacherDao.insertTeacher(TeacherDao.java:39)
	at cn.edu.wut.jwms.testDao.testTeacherInsert(testDao.java:14)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)

Error reporting location code:

public boolean insertTeacher(Teacher teacher)  {
        boolean b = false;

        try {
            //get the connection
            Connection connection = JDBCUtil.getConn();

            String sql = "INSERT INTO tb_teacher(teacher_num,teacher_pwd,teacher_name,teacher_tel,teacher_col_id) VALUES(?,?,?,?,?)";
            //compile
            PreparedStatement ps = connection.prepareStatement(sql);

            //Assigning values to placeholders
            ps.setString(1,teacher.getTeacherNum());
            ps.setString(2,teacher.getTeacherPwd());
            ps.setString(3,teacher.getTeacherName());
            ps.setString(4,teacher.getTeacherTel());
            ps.setInt(5,teacher.getTeacherColId());

            int i = ps.executeUpdate(sql);//Number of rows affected by the update operation on the data

            b = i>0?true:false;

            //close the connection
            connection.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return b;
    }

Process: check the SQL statements for many times and no errors are found. The test data is also checked for many times to confirm that the rules formulated during table creation are met;

Result.

int i = ps.executeUpdate(sql); because in this code, pass in the sql statement again to report an error, modified to
int i = ps.executeUpdate();; after the error is resolved.
Reason: The sql statement has already been passed in when the compile operation is executed, so it does not need to be passed in again when it is executed.

[Solved] java.lang.IllegalAccessError: class org.springframework.data.redis.core.$ Proxy237 cannot access its superinterface org.springframework.data.redis.core.RedisConnectionUtils$RedisConnectionProxy

[resolved]

java.lang.IllegalAccessError: class org.springframework.data.redis.core.$ Proxy237 cannot access its superinterface org.springframework.data.redis.core.RedisConnectionUtils$RedisConnectionProxy

In the serviceImpl class operation redis reported the above error, after investigation found that the cause is in the (with write operation [@Transactional (readOnly = false)]) transaction method of operation redis, in the readOnly = true transaction method can be operated normally

ps: other versions of redis do not know if there is also this situation for the time being

solution: the operation of redis to get @Transactional (readOnly = false) method outside the operation can be