Tag Archives: java

Spring project import @Resource Annotation Error [How to Solve]

An error is reported after the @resource annotation is introduced into the spring project

Solution:

@Resource annotations are provided by J2EE

However, jdk1.9 and above versions need to import a javax.annotation dependency package from pom.xml in maven:

<dependencies>
    <dependency>
        <groupId>javax.annotation</groupId>
        <artifactId>javax.annotation-api</artifactId>
        <version>1.3.2</version>
    </dependency>
</dependencies>

Tinyint error: java.lang.NullPointerException… [How to Solve]

Tinyint error reporting record
I wrote the wrong set before, which is easy to use when it is written as setid, and then I changed it to setType to report an error, and then I transformed it down to byte. After the change, it will be null pointer. Below are the error reporting information and error reporting line position




Finally, change the position as follows. Change the type from integer to string to solve the problem
the specific principle is not clear. For the time being, record it first. A great God who knows the principle can leave a message. Thank you

[Solved] Jxls error: Cannot load XLS transformer. Please make sure a Transformer implementation is in classpath

Note the problems encountered in using Jxls in the project

Cannot load XLS transformer. Please make sure a Transformer implementation is in classpath

Check whether components such as easyexcel are introduced into the project
if so, it needs to be excluded

<dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>easyexcel</artifactId>
      <version>2.2.10</version>
      <exclusions>
        <exclusion>
          <artifactId>poi</artifactId>
          <groupId>org.apache.poi</groupId>
        </exclusion>
        <exclusion>
          <artifactId>poi-ooxml</artifactId>
          <groupId>org.apache.poi</groupId>
        </exclusion>
        <exclusion>
          <artifactId>poi-ooxml-schemas</artifactId>
          <groupId>org.apache.poi</groupId>
        </exclusion>
      </exclusions>
    </dependency>

Then
the POI component 4 version is introduced

    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi</artifactId>
      <version>4.1.2</version>
    </dependency>
    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi-ooxml</artifactId>
      <version>4.1.2</version>
    </dependency>
    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi-ooxml-schemas</artifactId>
      <version>4.1.2</version>
    </dependency>

Because the project is iterative, complex excel is exported. Easyexcel can not meet the requirements. You can consider processing complex logic in the form of Jxls template.
it can solve the function of Excel processing by block, horizontal and column
official website: http://jxls.sourceforge.net/

In theory, it is not recommended to use several excel components at the same time. The idea plug-in Maven helper is recommended here to facilitate conflict handling.

When a problem is inexplicable and can not be solved by how to change it, see if there is a package conflict and if there is a problem with the network itself.

whitelabel error page SpEL RCE vulnerability recurrence [How to Fix]

Causes of loopholes

Normally, you can access/article and enter a numeric ID to get the article content. However, if a spel expression is passed in, you will go to the error page and parse the spel expression content and reflect it in the error page.

Debug process

Similarly, starting from the dispatcherservlet.Dodispatch() function, we quickly located the key class: propertyplaceholderhelper class
in dispatcherservlet, an error is reported due to the following judgment:

protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception {
...
		if (asyncManager.isConcurrentHandlingStarted()) {
		                    return;
		                }
...
}

The error content is numberformatexception, which converts the entered value into a digital error.

First look at the propertyplaceholderhelper.Parsestringvalue() method

rotected String parseStringValue(String strVal, PropertyPlaceholderHelper.PlaceholderResolver placeholderResolver, Set<String> visitedPlaceholders) {
        StringBuilder result = new StringBuilder(strVal);
        int startIndex = strVal.indexOf(this.placeholderPrefix);

        while(startIndex != -1) {
            int endIndex = this.findPlaceholderEndIndex(result, startIndex);
            if (endIndex != -1) {
                String placeholder = result.substring(startIndex + this.placeholderPrefix.length(), endIndex);
                String originalPlaceholder = placeholder;
                if (!visitedPlaceholders.add(placeholder)) {
                    throw new IllegalArgumentException("Circular placeholder reference '" + placeholder + "' in property definitions");
                }

                placeholder = this.parseStringValue(placeholder, placeholderResolver, visitedPlaceholders);
                //Here
                String propVal = placeholderResolver.resolvePlaceholder(placeholder);
                if (propVal == null && this.valueSeparator != null) {
                    int separatorIndex = placeholder.indexOf(this.valueSeparator);
                    if (separatorIndex != -1) {
                        String actualPlaceholder = placeholder.substring(0, separatorIndex);
                        String defaultValue = placeholder.substring(separatorIndex + this.valueSeparator.length());
                        propVal = placeholderResolver.resolvePlaceholder(actualPlaceholder);
                        if (propVal == null) {
                            propVal = defaultValue;
                        }
                    }
                }

                ......
        }

        return result.toString();
    }

After that, it will return to the view, which contains ${timestamp}, ${error}, ${status}, and ${message}. The view will judge whether the value starts with “${” through circular traversal

As long as it starts with “${“, it will enter the spel expression execution stage. However, when we set the value of message to payload, which also starts with “${“, it will also execute payload. It does not verify the value of controllable parameter message.

After that, use the errormvcautoconfiguration.Resolveplaceholder() method to parse the spel expression and get the value.

this step is to get the value of status. When the payload is reached, it will be parsed into the runtime class and execute the exec method. This step is to get the runtime instance through reflection.

Summary

Because the value passed in will determine whether it is a number, if it is not a number, an error will be reported and you will enter the error page. The error page contains some spel expressions, so the spel expressions in the error page will be searched and parsed in a loop, and finally rendered to the page. However, the reason for the problem is ${messgae} If the value of is also a spel expression, it will continue to parse the expression circularly, so as to achieve command injection, that is, the user-controllable parameters are not verified.

Repair suggestions

The reason is that the ID is not filtered in the spel direction. Therefore, I summarize and suggest the following points:

    filter IDS, set black-and-white lists, filter values such as ${, upgrade the Framework version, patch, and customize the error page

Android Studio Error: Error:moudle not specified [How to Solve]

Android studio solves error: mouse not specified

When using Android studio for builder apks, if you find that you can’t degub,

No module can be specified during configuration, as shown in (borrow a figure)

The reason for the problem is that the grade files are not synchronized effectively.

1. First ensure grade Synchronization is complete.

2. Perform manual synchronization

Old as version   Click Tools – > Android—> Sync Project With Gradle Files

The new version (I am the new version) is shown in the figure:

Generally, you can debug, and the module has been configured

[Solved] Error: A JNI error has occurred, please check your installation and try again

This problem probably occurs because the JDK versions are inconsistent, and the jar package will have signature files, which does not affect the logic of the program, but will cause the test demo to fail. Therefore, you need to delete the signature related files in the jar package

error condition

It is the .DSA under meta-inf\   And files with .SF suffix can be deleted

Done!

[Solved] IDEA Error: java Compilation failed internal java compiler error

Java: compilation failed: internal java compiler error

Write an article to record the painful experience of finding an idea error for half an hour

java: Compilation failed: internal java compiler error

The solution is as follows:

①: check item configuration

②: module configuration

③: The most important step. This setting solves the problem

Next step. This setting solves the problem

I/O error while reading input message; nested exception is java.io.IOException: Stream closed

SpringMVC control layer receives multiple front-end parameters
Report an error I/O error while reading input message; nested exception is java.io.IOException: Stream closed
[Controller]

	@PostMapping("/list")
    public Result<List<ReviseInfo>> list(@RequestBody ReviseInfo reviseInfo, @RequestBody ReviseRequest reviseRequest){
        return reviseAdaptor.list(reviseInfo, reviseRequest);
    }

ReviseInfo

@Data
public class ReviseInfo {
    /** Primary key Id */
     @MongoId
     private String id;
     /** Manuscript Id */
     private String subjectId;
     /** Version Id */
     private String versionId;
     /** Suspected error */
     private String fragOri;
     /** Suggested adjustment */
     private String fragFixed;
     /** 1-Unprocessed 2-Ignored 3-Corrected (3 not stored in the library)*/
    private Integer type;
}

ReviseRequest)

@Data
public class ReviseRequest {
	/** Error correction content list */
     private List<ReviseContent> data;
}

Transmission parameter

{
// Current manuscript ID
     "subjectId": "5f4b7a6cc04e43398921421aef8b77a2",
     // Error correction content list
     "data": [
         {
             "content": "Ningxia's good time record plans to investigate"
        }
    ]
}

Error I/O error while reading input message; Needed exception is java.io.ioexception: stream closed
solution
1. Create a new data transmission object, such as revisedto, and merge the required parameters into a dto
[revisedto]

@Data
public class ReviseDTO {
	/** Manuscript Id */
     private String subjectId;
/** Error correction content list */
    private List<ReviseContent> data;
}

[Controller]

	@PostMapping("/list")
    public Result<List<ReviseInfo>> list(@RequestBody ReviseDTO reviseDTO){
        return reviseAdaptor.list(reviseDTO);
    }

2. Use map < String, Object> Receive multiple parameters
[controller]

	@PostMapping("/list")
    public Result<List<ReviseInfo>> list(@RequestBody Map<String, Object> params){
        return reviseAdaptor.list(params);
    }

[Adaptor/serviceImpl]

import org.apache.commons.collections4.MapUtils;

	String subjectId = MapUtils.getString(params, "subjectId");
	List<ReviseContent> data = (List<ReviseInfo>)MapUtils.getObject(params, "data");
	// List<ReviseInfo> data = (List<ReviseInfo>)params.get("data");

(error) READONLY You can‘t write against a read only replica.

Because the master-slave replication cluster was configured before, the configuration was changed disorderly

There are two solutions:

1. Open the configuration file corresponding to the redis service, and change the value of the attribute slave read-only to no, so that it can be written.

2. Open the client mode through the redis cli command, and enter the slave of no one command

Registry key Error: Java version has value ‘1.8‘, but ‘1.7‘ is required

Registry key Error: Java version has value ‘1.8’, but ‘1.7’ is required

Problem Description:

1. Jdk1.7.0 is installed first_ After 80, jdk1.8.0 was installed_ 181. The former is configured in the environment variable
2. The following error occurs when entering Java – version in CMD:

Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'
has value '1.7', but '1.8' is required.
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.

Problem solving:

When upgrading from jdk1.7 to JDK1.8, there are three things to confirm:

1. System environment variables

2. Registry

Computer \ HKEY_ LOCAL_ MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment

3. Update java.exe javaw.exe javaws.exe under C: \ windows \ system32

Error caused by too many versions of JDK installed on the computer

For example, there was no problem installing 1.7

After installing 1.8 and modifying the environment variables, the java.exe javaw.exe javaws.exe under C: \ windows \ system32 is still in the 1.7 installation package.

Just replace the java.exe of 1.7 with Java 1.8.