Tag Archives: spring

Spring boot problem 1: error reporting life processing instructions for building a spring boot project

Operating environment

System: Windows 10

jdk:1.7

Development tool: Eclipse 4.6

Springboot version: 1.5.3
version

Build tool: Maven
0

Problems and their background

At the beginning of learning to build a spring boot project, the problems encountered.

After creating a new Maven project, add the pom.xml The file reported an error when adding the parent node (the content is as follows).

<parent>
<groupId> org.springframework.boot&lt ;/groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>

The error information is as follows:

Error parsing lifecycle processing instructions

terms of settlement

According to the search results, two ideas are found

1. It is said that there is a problem with this version of eclipse, and the Maven plug-in needs to be updated.

2. It is said that there is a dependency conflict. You can clear the Maven warehouse and update it again.

The first method was tried, but it didn’t solve the problem. So we tried the second method to clear all the dependencies under. M2/repository/in the user’s home directory. Then, in eclipse, right-click the project — & gt; Maven — & gt; update project. After waiting for the update to complete, the error disappears automatically.

Error picture information:

Spring AOP is an error creating bean with name

Some error messages are as follows:

Warning: exception encoded during context initialization – canceling refresh attempt: org.springframework.beans . factory.BeanCreationException : Error creating bean with name ‘duke’ defined in class path resource [com/springinaction/springidol/spring- idol.xml ]

The reason for this problem is that the necessary jar package is missing aspectjweaver.jar , just download it.

Please click here for the download interface of aspectjweaver

Here’s how to download it:

Select the version you need. Here, select version 1.9.1. After entering, as shown in the figure below, click the box on the way to download the responding jar package, and finally pour it into the project.

Springboot startup error – classnotfound Exception:EnhancerBySpringCGLIB

Error classnotfound in springboot startup Exception:EnhancerBySpringCGLIB

Error information solution

Error information

Spring boot 2.4.1 project, start to report the following error, but start will be normal, although it does not affect the use, but look very boring.

java.lang.ClassNotFoundException: cn.demo.Application$$EnhancerBySpringCGLIB$$310af73e
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:264)
	at cn.demo.ocean.common.prop.core.spring.SpringConfigPropertiesHandle.handleSpringConfig(SpringConfigPropertiesHandle.java:47)
	at cn.demo.ocean.common.prop.core.spring.ConfigServerPostProcessor.doProcessProperties(ConfigServerPostProcessor.java:305)
	at cn.demo.ocean.common.prop.core.spring.ConfigServerPostProcessor.processProperties(ConfigServerPostProcessor.java:122)
	at cn.demo.ocean.common.prop.core.spring.ConfigServerPostProcessor.postProcessBeanFactory(ConfigServerPostProcessor.java:102)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:299)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:170)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:751)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:569)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:326)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298)
	at cn.demo.Application.main(Application.java:19)
	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.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
java.lang.ClassNotFoundException: cn.demo.config.Swagger2Config$$EnhancerBySpringCGLIB$$589bf224
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:264)
	at cn.demo.ocean.common.prop.core.spring.SpringConfigPropertiesHandle.handleSpringConfig(SpringConfigPropertiesHandle.java:47)
	at cn.demo.ocean.common.prop.core.spring.ConfigServerPostProcessor.doProcessProperties(ConfigServerPostProcessor.java:305)
	at cn.demo.ocean.common.prop.core.spring.ConfigServerPostProcessor.processProperties(ConfigServerPostProcessor.java:122)
	at cn.demo.ocean.common.prop.core.spring.ConfigServerPostProcessor.postProcessBeanFactory(ConfigServerPostProcessor.java:102)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:299)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:170)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:751)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:569)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:326)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298)
	at cn.demo.Application.main(Application.java:19)
	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.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)

solve

Baidu has failed for many times, so we can only read the error report carefully. Last line found:

at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)

Doubt is the problem of devtools, and then pom.xml Devtools dependency removal in

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
    <optional>true</optional>
</dependency>

It’s solved (⊙ o ⊙)

Spring nested exception is java.lang.NoClassDefFoundError: org/springframework/core/MethodClassKey

1、 Questions

Build your own batch task framework, and then report an error

- Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.event.internalEventListenerProcessor': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/core/MethodClassKey
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.event.internalEventListenerProcessor': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/core/MethodClassKey
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
	at com.caliper.tail.batch.common.BatchApp.start(BatchApp.java:85)

2、 Solution

The spring core package is not imported; just go to Maven repository and import the jar package of spring core;

<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>5.1.5.RELEASE</version>
</dependency>

[spring] springboot failed to install cli, unsupportclassversionerror 52.0

1、 Error information

Install springboot cli yesterday:
1. Download and unzip it directly from the official website;
2. Add the bin directory absolute path of the unzipped folder to the environment variable path;
3. Enter “ spring -- version " in the CMD to verify whether the installation is successful;

However, an error was reported during verification. The error information is as follows:

UnsupportClassVersionError:org/springframework/boot/loader/JarLauncher:Unsupporyed major.minor version 52.0
......
Could not find the main class

2、 Solutions

2.1. You need to set the JDK version

2.2. There are two ways to modify the language level, one is to click project structure, which is the button in the upper right corner of idea;

Modify JDK version and language level in project:

Modify the language level in modules:

3、 Results

Then there is no problem

Spring security failed to log in, error: there is no passwordencoder mapped for the ID “null”

After writing the websecurityconfig class that inherits the websecurityconfigureradapter class, we need to define authentication in the configure (authentication manager builder auth) method, which is used to obtain information sources and password verification rules. (the name of the configure function doesn’t matter. The official name seems to be configureglobal (…) )It is important to configure the authenticationmanagerbuilder in the class annotated by @ enablewebsecurity or @ enableglobalmethodsecurity or @ enableglobalauthentication).

The source of authentication information I used at the beginning was in memory authentication. The code is as follows

 
    protected void configure (authentication manager auth) throws exception { // inmemoryauthentication gets from memory auth.inMemoryAuthentication ().withUser("user1").password("123456").roles("USER"); }

The login page of spring security is used. As a result, when logging in, the user name and password are correct, and the resource cannot be opened, so it still stays on the login page. There is no passwordencoder mapped for the ID "null".

Baidu found that this is because spring security 5.0 added a variety of encryption methods, but also changed the password format.

Let's take a look at the official documents. Here are the original words of the official documents:

 

-------------------------------------------------------------------------------------------------------------------

The general format for a password is:

{id}encodedPassword

Such that id is an identifier used to look up which PasswordEncoder should be used and encodedPassword is the original encoded password for the selected PasswordEncoder. The id must be at the beginning of the password, start with { and end with }. If the id cannot be found, the id will be null. For example, the following might be a list of passwords encoded using different id. All of the original passwords are "password".

{bcrypt}$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG 
{noop}password 
{pbkdf2}5d923b44a6d129f3ddf3e3c8d29412723dcbde72445e8ef6bf3b508fbf17fa4ed4d6b99ca763d8dc 
{scrypt}$e0801$8bWJaSu2IKSn9Z9kM+TPXfOc/9bdYSrN1oD9qfVThWEwdRTnO7re7Ei+fUZRJ68k9lTyuTeUp4of4g24hHnazw==$OAOec05+bXxvuu/1qZ6NUR+xQYvYv7BeL1QxwRpY5Pc=  
{sha256}97cde38028ad898ebc02e690819fa220e88c62e0699403e94fff291cfffaf8410849f27605abcbc0

-------------------------------------------------------------------------------------------------------------------

 

The storage format of passwords in spring security is "{ID}.....". The front ID is the encryption method, the ID can be bcrypt, sha256, etc., followed by the encrypted password. In other words, when the program gets the passed password, it will first find the ID included by "{" and "}" to determine how the subsequent password is encrypted. If it cannot be found, it will be considered that the ID is null. This is why our program will report an error: there is no passwordencoder mapped for the ID "null". In the example of official documents, various encryption methods are used to encrypt the same password. The original password is "password".

 

If we want our project to log in normally, we need to modify the code in configure. We need to encrypt the password from the front end in some way. Spring security officially recommends using bcrypt encryption. So how to encrypt the password?Just specify it in the configure method.

After modification, it looks like this:

 
    protected void configure (authentication manager auth) throws exception { // inmemoryauthentication gets from memory auth.inMemoryAuthentication ().passwordEncoder(new BCryptPasswordEncoder()).withUser("user1").password(new BCryptPasswordEncoder().encode("123456")).roles("USER"); }

After inmemoryauthentication(), there is ". Passwordencoder (New bcryptpasswordencoder())", which is equivalent to using bcrypt encryption to process the user password when logging in. The previous ". Password (" 123456 ")" is changed to ". Password (New bcryptpasswordencoder(). Encode (" 123456 ")", which is equivalent to bcrypt encoding and encryption of the password in memory. The comparison is consistent, which indicates that the password is correct and login is allowed.

If you are also using the password from the memory, then according to the above modification should be successful login, no problem.

If you use to store the user name and password in the database, you usually use bcrypt code to encrypt the user password and store it in the database. And modify the configure() method, add ". Passwordencoder (New bcryptpasswordencoder())" to ensure that users use bcrypt to process the password when they log in, and then compare it with the password in the database. As follows:

 
    // inject the implementation class of userdetailsservice auth.userDetailsService (userService).passwordEncoder(new BCryptPasswordEncoder());
     

reprint https://blog.csdn.net/canon_ in_ d_ major/article/details/79675033

org.springframework.orm . hibernate3. Hibernatequeryexception: XXX is not mapped solution

There are several reasons as follows:
1

1. The HBM file association in spring is not configured well.

2. The fields in the HBM file are missing.

Solution:

1. Add fully qualified domain name when writing HQL (not recommended)

2. Configure HBM Association in spring (20 has been like this for several times)
in this paper, we introduce a new method to configure HBM Association in spring

web.xml Solution of < async supported > true < / async supported > error in configuration file

I’m writing web.xml I always reported cvc-complex-type. 2.4. A: invalid content was found starting with element error again. I also found a small red cross. I found a lot of Red Cross on the Internet. It was said that I wrote the code of red cross between & lt; JSP config & gt; & lt; & JSP config & gt;, but it was useless after trying. Then I found a solution to the problem on the foreign language website

Solution 1:
configure XML in eclipse
1 http://www.springmodules.org/schema/cache/springmodules-cache.xsd
   2、 http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd
and then add these two xsds to the web.xml The code is as follows:

web.xml code

    <?xml version=”1.0″ encoding=”UTF-8″?>   < web-app version=”2.4″ xmlns=” http://java.sun.com/xml/ns/j2ee ”        xmlns:xsi= ” http://www.w3.org/2001/XMLSchema-instance    http://www.springmodules.org/schema/cache/springmodules-cache.xsd   http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd ”     xsi:schemaLocation= ” http://java.sun.com/xml/ns/j2ee    http://java.sun.com/xml/ns/j2ee/web-app_ 2_ 4.xsd”>       <!–OS Work Flow –>       <display-name>OSWorkflow Example App</display-name>       <description>OSWorkflow Example App</description>                <servlet>           <servlet-name>SOAPWorkflow</servlet-name>           < servlet-class>                com.opensymphony.workflow . soap.SOAPWorkflowServlet            </servlet-class>       </servlet>       <servlet>           <description>               This is the description of my J2EE component           < /description>           <display-name>               This is the display name of my J2EE component           </display-name>           <servlet-name>Osworkflow</servlet-name>           <servlet-class> net.caiban.servlet .Osworkflow</servlet-class>        </servlet>       <servlet>           <description>               This is the description of my J2EE component           </description>           <display-name>                This is the display name of my J2EE component           </display-name>           <servlet-name>DoWorkflow</servlet-name>           <servlet-class> net.caiban.servlet .DoWorkflow</servlet-class>       </servlet>       <servlet>            <description>               This is the description of my J2EE component           </description>           <display-name>               This is the display name of my J2EE component           </display-name>            <servlet-name>CreateWorkflow</servlet-name>           <servlet-class> net.caiban.servlet .CreateWorkflow</servlet-class>       </servlet>                   <servlet-mapping>           <servlet-name>SOAPWorkflow</servlet-name>            <url-pattern>/soap/*</url-pattern>       </servlet-mapping>          <servlet-mapping>           <servlet-name>Osworkflow</servlet-name>           <url-pattern>/servlet/Osworkflow</url-pattern>       </servlet-mapping>        <servlet-mapping>           <servlet-name>DoWorkflow</servlet-name>           <url-pattern>/servlet/DoWorkflow</url-pattern>       </servlet-mapping>       <servlet-mapping>           <servlet-name>CreateWorkflow</servlet-name>            <url-pattern>/servlet/CreateWorkflow</url-pattern>       </servlet-mapping>          <welcome-file-list>           <welcome-file> default.jsp&lt ;/welcome-file>           <welcome-file> index.jsp&lt ;/welcome-file>       </welcome-file-list>        <resource-ref>           <res-ref-name>jdbc/oswf</res-ref-name>           <res-type> javax.sql.DataSource&lt ;/res-type>           <init-param driverClassName=” com.mysql.jdbc .Driver” />           <init-param url=” jdbc:mysql :// localhost:3306/osworkflow ” />            <init-param user=”root” />           <init-param password=”123465″ />           <init-param max-connections=”20″ />           <init-param max-idle-time=”30″ />       </resource-ref>       <!–OS Work Flow –>   </web-app>  

Solution 2:

≪ async supported & gt; true & lt;/async supported & gt; yes web.xml 3.0, just add

<web-app xmlns:xsi= ” http://www.w3.org/2001/XMLSchema-instance ” xmlns=” http://Java.sun.com/xml/ns/javaee ” xsi:schemaLocation= ” http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_ 2_ 5.xsd” id=”WebApp_ ID” version=”2.5″>

Change to:

<web-app xmlns:xsi= ” http://www.w3.org/2001/XMLSchema-instance ” xmlns=” http://java.sun.com/xml/ns/javaee ” xsi:schemaLocation= ” http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_ 3_ 0.xsd” id=”WebApp_ ID” version=”3.0″>

It can be solved.

Original address: http://blog.csdn.net/zxz547388910/article/details/50780068

Idea access denied for user ‘xxx’ @ ‘localhost’ solution

Solutions to access denied for user ‘xxx’ @’localhost ‘problem

Key to error reporting

java.sql.SQLException : access denied for user ‘xxx’ @’localhost ‘(using password: Yes). Note that XXX here is not root, root is a permission problem

Solution

Change the user name for the configuration file

You can choose any name you like

And then 🆗 It’s over

Cause analysis

The framework did not get the correct user name of datasource, which is related to the configuration. When such a framework constructs an instance of abstractdriverbaseddatasource, the user name it gets is always the current machine name, that is, XXX. The underlying reason is not clear.

Spring ApplicationContext – Resource leak: ‘context’ is never closed

Compiling environment: Eclipse

Problem: in spring MVC applications, I use the following method to initialize variables in one of the service classes

ApplicationContext context=new ClassPathXmlApplicationContext("Beans.xml");
HelloWorld obj=(HelloWorld) context.getBean("helloWorld");
obj.getMessage();

In the first line of the above code, the ‘context’ variable generates a warning. The warning is as follows:

Resource leak: 'context' is never closed

Solution: because ApplicationContext has an instance of classpathxmlapplicationcontext, it has a close () method. We just need to throw the context object and call the close () method, as shown below.

((ClassPathXmlApplicationContext) context).close();

In addition, if the ApplicationContext uses an abstractapplicationcontext instance, you need to throw the context object of that type and call the close () method.

import org.springframework.context.support.AbstractApplicationContext;
    ...
    ...
    ...
    ...
((AbstractApplicationContext) context).close();

 

Mybatis idea environment integration jar package

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.47</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.3.4</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.3.4</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.8.13</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>2.0.2</version>
        </dependency>
    </dependencies>