Tag Archives: java

[Solved] error running ‘xx‘ Command line is too long shorten command line for xx or also for Spring Boot defa

Problem description:

This problem occurred when the idea started the microservice project, causing the project to fail to start

error running ‘xx’ Command line is too long shorten command line for xx or also for Spring Boot default configuration.

Solution:

My idea uses the 2019 version.

Step 1: Open edit Configurations

Step 2:

Modify shorten command line to JAR manifest.

Restart, complete.

[Solved] Cannot run program “svn” (in directory “D: xxxx”): CreateProcess error=2, the system cannot find the specified file.

 

1. Error content

Cannot run program “svn” (in directory “xxxx”): CreateProcess error=2, the system cannot find the specified file

2. Reason

The command was not installed when TortoiseSVN was installed, so version management cannot be performed through the command

3. Solution

1. Find the TortoiseSVN installation package you downloaded at that time and reinstall it

2. Select the first one here

3. The second option is X, which means that you have not installed the command. Click on and check the first one, and then confirm the next step

Uncaught URIError: URI malformed [How to Solve]

Uncaught URIError: URI malformed

  • url, pass the value, if the key has Chinese characters inside, the browser will be encoded off by default, so this page needs to be decoded first when calling the query interface), the above error occurs.
  • Because the url contains the “%” character, the browser will give an error when it executes decodeURIComponent on “%”.

Repeat the problem

The browser url on the splice on (?q=%好的);

https://www.baidu.com/?q=%好的

Enter the code;

location.search
'?q=%%E5%A5%BD%E7%9A%84'
decodeURIComponent('%%E5%A5%BD%E7%9A%84');

Solution

urlStr.replace(/%/g, '%25');

Fundamentally solve the problem: encode the URL before uploading the value

encodeURIComponent('%好的');
'%25%E5%A5%BD%E7%9A%84'
https://www.baidu.com/?q=%25%E5%A5%BD%E7%9A%84

[Solved] Error: unable to perform an operation on node ‘rabbit@DESKTOP-xxx‘. Please see diagnostics informa

1. Recurrence problem

Today, I logged in to the rabbitmq background management. After inputting the user name and password, this error was reported: not management user, as shown in the following figure:

So I decided to execute the command rabbitmqctl list_users check whether there is this user.

  1. First D:\Software\rabbitmq\rabbitmq_server-3.8.15\sbinenter in the directory cmd:

  1. Execute the following command in the cmdcommand window:
rabbitmqctl list_users

But the following error is reported:

D:\Software\rabbitmq\rabbitmq_server-3.8.15\sbin>rabbitmqctl list_users
Error: unable to perform an operation on node 'rabbit@DESKTOP-UVTEHFR'. Please see diagnostics information and suggestions below.

Most common reasons for this are:

 * Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)
 * CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server)
 * Target node is not running

In addition to the diagnostics info below:

 * See the CLI, clustering and networking guides on https://rabbitmq.com/documentation.html to learn more
 * Consult server logs on node rabbit@DESKTOP-UVTEHFR
 * If target node is configured to use long node names, don't forget to use --longnames with CLI tools

DIAGNOSTICS
===========

attempted to contact: ['rabbit@DESKTOP-UVTEHFR']

rabbit@DESKTOP-UVTEHFR:
  * connected to epmd (port 4369) on DESKTOP-UVTEHFR
  * epmd reports: node 'rabbit' not running at all
                  no other nodes on DESKTOP-UVTEHFR
  * suggestion: start the node

Current node details:
 * node name: 'rabbitmqcli-999-rabbit@DESKTOP-UVTEHFR'
 * effective user's home directory: C:\Users\zxy
 * Erlang cookie hash: pkFzX53V7Ok1QDOYqiMzXg==

3. Solving problems

Copy the .erlang.cookie file from the C:\user\your username\ directory to the C:\Windows\System32\config\systemprofile\ directory, as follows:

If the .erlang.cookie file already exists in C:\Windows\System32\config\systemprofile\, just use the .erlang.cookie file in the C:\user\your username\ directory to replace it.

Double-click rabbitmq-server.bat to restart the rabbitmq service, as shown in the following image:


In the cmd command line window, enter rabbitmqctl list_users again:

[Solved] springsecurity custom exceptions: Error: Parse Error: Response overflow

preface

In the process of writing the project, using springsecurity for permission management and customizing the token filter to be added before the authentication filter, there was a problem where the exception handling mechanism of springsecurity would be called when the token expired, instead of using my global exception handling

Solution:

Custom filter

package com.fruiter.filter;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.jsonwebtoken.ExpiredJwtException;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Handling exceptions thrown by Controller will be handled by this filter
 */
public class ControllerExceptionFilter extends OncePerRequestFilter {

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        try {
            filterChain.doFilter(request, response);
        } catch (ExpiredJwtException e) {
            e.printStackTrace();

            response.setStatus(401);
            response.setContentType("application/json");
            response.setCharacterEncoding("utf-8");
            response.getWriter().print("token过期");
        }
    }

    public String convertObjectToJson(Object object) throws JsonProcessingException {
        if (object == null) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        return mapper.writeValueAsString(object);
    }
}

Join for management

//WebAsyncManagerIntegrationFilter is the first exception handling filter
http.addFilterBefore(new ControllerExceptionFilter(), WebAsyncManagerIntegrationFilter.class);

be careful

Here, set the status code for response, that is, response.setStatus(401);
you can’t set an excessively large number such as 10010, otherwise an error will report error: parse error: response overflow

Modify it to 401.

[Solved] Error occurred during initialization of VM javalangNoClassDefFoundError javalangObject

When you run java/javac/java -version under the doc command, an error was reported:

Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object

 

Or eclipse cannot be opened for this reason

I summarized the following three reasons:

1: java environment variables are misconfigured, check the right and wrong environment variables, especially check the classpath

General (in the case of java configuration only), the value of the environment variable

JAVA_HOME ========= “your jdk installation directory” such as “C:Program FilesJavajdk1.8.0_121”

Path ========= “%JAVA_HOME%in;%JAVA_HOME%jrein”

CLASS_PATH ========= “%JAVA_HOME%libdt.jar;%JAVA_HOME%lib ools.jar”

2: If there is no problem with the environment variable configuration, then go to the jdk installation directory (such as C:Program FilesJavajdk1.8.0_121) and look for tools.jar under lib and rt.jar under jrelib to see if they exist, it is possible that rt.pack and tools.pack exist.

At this point, just unpack the corresponding files into rt.jar and tools.jar, and you can use the unpack200 tool inside the bin

#cd /usr/java/j2sdk1.4.2/lib
#unpack tools.pack tools.jar
#cd …/jre/lib
#…/…/unpack rt.pack rt.jar

3: There is no tools.jar under lib or rt.jar under jrelib, or there are missing files under lib or jrelib (40 files), so just copy them from elsewhere.

If you run java command after copying tools.jar or rt.jar, there may be missing files under jrelib, look carefully or just copy a whole jrelib, it can be solved.

[Solved] java Internal error in the mapping processor java.lang.NullPointerException

Error:

java: Internal error in the mapping processor: java.lang.NullPointerException  	
at org.mapstruct.ap.internal.processor.DefaultVersionInformation.createManifestUrl(DefaultVersionInformation.java:182)  	
at org.mapstruct.ap.internal.processor.DefaultVersionInformation.openManifest(DefaultVersionInformation.java:153)  	
at org.mapstruct.ap.internal.processor.DefaultVersionInformation.getLibraryName(DefaultVersionInformation.java:129)  	
at org.mapstruct.ap.internal.processor.DefaultVersionInformation.getCompiler(DefaultVersionInformation.java:122)  	
at org.mapstruct.ap.internal.processor.DefaultVersionInformation.fromProcessingEnvironment(DefaultVersionInformation.java:95)  	
at org.mapstruct.ap.internal.processor.DefaultModelElementProcessorContext.<init>(DefaultModelElementProcessorContext.java:50)  
at org.mapstruct.ap.MappingProcessor.processMapperElements(MappingProcessor.java:218)  	
at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:156)  	
at org.jetbrains.jps.javac.APIWrappers$ProcessorWrapper.process(APIWrappers.java:109)  	
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.jetbrains.jps.javac.APIWrappers$1.invoke(APIWrappers.java:213)  	
at org.mapstruct.ap.MappingProcessor.process(Unknown Source)  	
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)  	
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)  
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)  	
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)  	
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)  	
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)  	
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)  	
at com.sun.tools.javac.main.Main.compile(Main.java:523)  	
at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)  	
at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)  	
at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:231)  	
at org.jetbrains.jps.incremental.java.JavaBuilder.compileJava(JavaBuilder.java:501)  	
at org.jetbrains.jps.incremental.java.JavaBuilder.compile(JavaBuilder.java:353)  	
at org.jetbrains.jps.incremental.java.JavaBuilder.doBuild(JavaBuilder.java:277)  	
at org.jetbrains.jps.incremental.java.JavaBuilder.build(JavaBuilder.java:231)  	
at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1441)  	
at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:1100)  	at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:1224)  	at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:1066)  	at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:832)  	at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:419)  	at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:183)  	at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:132)  	at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:302)  	at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:132)  	at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.lambda$channelRead0$0(BuildMain.java:219)  	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)  	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)  	at java.lang.Thread.run(Thread.java:748)  

When using MapStruct, idea version 2020.3, an error occurs when building the project: java: Internal error in the mapping processor: java.lang.NullPointerException

Solution:
Setting –>Build,Execution,Deployment –>Compiler –>User-local build add the parameter
-Djps.track.ap.dependencies=false

[Solved] docker Error response from daemon driver failed programming external connectivity on endpoint lamp

Docker containers do port mapping error:

docker: Error response from daemon: driver failed programming external connectivity on endpoint lamp3 (46b7917c940f7358948e55ec2df69a4dec2c6c7071b002bd374e8dbf0d40022c): (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 86 -j DNAT --to-destination 172.17.0.2:80 ! -i docker0: iptables: No chain/target/match by that name.

 

Solution:

The custom chain DOCKER defined at the start of the docker service is cleared

Restart and it will be OK! systemctl restart docker

[Solved] ant-design a-date-picker Error: date.locale is not a function

The error reporting contents are as follows:

date.locale is not a function

Original code:

<a-form-item label="Time From:" name="signTime">
                <a-date-picker placeholder="Please Select"  v-model:value="formState.signTime" style="width:100%" />
              </a-form-item>

Correct code:

<a-form-item label="Time From:" name="signTime">
                <a-date-picker placeholder="Please Select" format="YYYY-MM-DD" valueFormat="YYYY-MM-DD" v-model:value="formState.signTime" style="width:100%" />
              </a-form-item>

Summary: you need to add the time display format attribute and the final value format valueFormat attribute.

[Solved] fastjson Error: com.alibaba.fastjson.JSONObject cannot be cast to xxxx

There is a StockData object. Normally, the JSON string to object should be:

StockData stockData = JSONObject.parseObject(str, StockData.class);

However, if the object is a generic (e.g. StockData<StockDetail>), it can be converted as above, but StockDetail throws an exception when it gets the object parameters via get com.alibaba.fastjson. JSONObject cannot be cast to cn.seagen.sorting.bean.StockDetail.

StockData<StockDetail> stockData = JSONObject.parseObject(str, StockData.class);

prompt JSONObject can not be converted to StockDetail object, the reason is probably.

fastjson conversion json object encounters a generic, it will not be correctly converted to a generic object, the converted object is a JSONObject object, not the object inside the generic, so there is also the above-thrown exception.

Solution

In addition to the above methods, fastjson also overloads a method.

public static <T> T parseObject(String text, TypeReference<T> type, Feature... features){}

Therefore, when the string is converted to a generic object, it is OK to use TypeReference for conversion. After conversion, StockDetail can normally get the parameter value of the object.

StockData<StockDetail> stockData = JSONObject.parseObject(str, new TypeReference<StockData<StockDetail>>(){});

How to Solve Mockito mockedStatic NotAMockException Error

Error Message:

org.mockito.exceptions.misusing.NotAMockException: Argument passed to Mockito.mockingDetails() should be a mock, but is an instance of class java.lang.Class!
    at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:52)
    at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:163)
    at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:53)

 

Solution:
Delete @RunWith(MockitoJUnitRunner.class)
and add

    @Before
    public void before(){
        log.info("start--------{}",this.getClass().getName());
         MockitoAnnotations.openMocks(this);
    }

mybatis-plus Common Error and Their Solution

2021/7/9


Error 1: there is no @EnumValue annotation when writing enumeration class

Solution 1: @EnumValueis an annotation supported after mybatis-plus version 3.0

 

Error 2:

java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class org.mybatis.spring.annotation.MapperScan.factoryBean()

Solution 2:

Modify the dependency from

<dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus</artifactId>
            <version>3.3.2</version>
        </dependency>

to

 <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.0.5</version>
        </dependency>

 

Error 3:
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘***’: Unsatisfied dependency

Solution 3:

Delete the dependency of mybaits

 <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.1.1</version>
        </dependency>

 

Error 4:

The list() method reports red, indicating that the parameter is missing,

Solution 4:

View source code

Method does require parameters

View official documents

It may be due to the version problem. In the latest version, you do not need to pass the parameter. The parameter should be null

Problem-solving

 

Error 5:

java.lang.IllegalArgumentException: No enum constant com.book.bookshop.entity.enums.Suit.1

Solution 5:

Removing spring-boot-devtools, this plug-in will cause many problems. It is estimated that it should be the main reason