Tag Archives: maven

Not registered via @EnableConfigurationProperties or marked as Spring component

In springboot, there are the following problems when binding the properties in the class with the configuration in the configuration file:

When using @ configurationproperties, the following prompt appears at the top of idea:

Click the prompt to jump to the official document, and then add the following configuration in POM. XML

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <optional>true</optional>
</dependency>

The effect after adding is that when you write the configuration file (YML, properties configuration file), you will be prompted

After the above is finished, @ configurationproperties will report an error below. You can see it according to the prompt

Not registered via @ enableconfigurationproperties or marked as spring component    @ Enable configuration properties (person. Class),

After adding, the error is really gone, but in the unit test of springboot, you will see the following error: could not autowire. No beans of ‘person’ type found

  Go back to the user-defined bean person, add the annotation @ component and declare to add the component to the container so that it can be used?

“Only if this component is a component in the container can the @ configurationproperties function provided by the container be used.”

[Solved] ‘build.plugins.plugin.version‘ for org.springframework.boot:spring-boot-maven-plugin is missing.


Some problems were encountered while building the effective model for org.example:cloud2021:pom:1.0-SNAPSHOT
'build.plugins.plugin.version' for org.springframework.boot:spring-boot-maven-plugin is missing. @ line 88, column 15
It is highly recommended to fix these problems because they threaten the stability of your build.
For this reason, future Maven versions might no longer support building such malformed projects.

Use idea to create spring boot project when some of the pits encountered, record

In the pom.xml file, the “spring boot Maven plugin” is red, and not found is displayed

Let’s look at a translation first

Go to line 87 and find the problem configuration

<plugin>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

I also saw some other people’s solutions on the Internet. Finally, I successfully solved them by specifying the version of spring boot Maven plugin. It is revised as follows:

<plugin>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-maven-plugin</artifactId>
	<version>2.2.6.RELEASE</version>
</plugin>

solve!!!

[Solved] Could not find resource COM / atguigu / Dao / studentdao.xm, the mapper file for storing SQL statements could not be found and an error occurred

The mapper file created by using the Maven project mybatis to operate the database is not put under the resource resource file. The following error occurs during compilation

org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in com\atguigu\dao\StudentDao.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com\atguigu\dao\StudentDao.xml

	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64)
	at com.atguigu.Test1.test01(Test1.java:23)
	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:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com\atguigu\dao\StudentDao.xml
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:121)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:98)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:78)
	... 24 more
Caused by: java.io.IOException: Could not find resource com\atguigu\dao\StudentDao.xml
	at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:114)
	at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:100)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:371)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:119)
	... 26 more



This is because the dao.xml file under the mapper file can not find the statement file to operate the database during compilation. There are two solutions to the problem.
the first one is to put the file to store the database statement under the resource file. Remember to modify the mybatis main configuration file

 	 <mappers>
        <mapper resource="com\zixi\dao\StudentDao.xml"/>
    </mappers>

    <!--    Modify your path directly to the following-->

    <mappers>
    <mapper resource="StudentDao.xml"/>
</mappers>
    

If you don’t want to modify and copy, you can directly add the Blid tag under the Maven configuration file and add the following content

  <build>
<!--        To solve the problem of writing sql statements in main.com.**. file, but when compiling, the xmlsql file error does not appear in out-->
        <resources>
            <resources>
                <directory>src/main/java</directory><! --directory where -->
                <includes><! --Includes directories where .properties, .xml files are scanned -->
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>

This is my own practice problems, the above content can only be used as a reference, hope to be useful to you. thank you

java: java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module @0x590

java: java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module @0x5909b5c9) cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module @0x5909b5c9
Solution:
Modify the lombok dependency version number in pom.xml to the latest version
If the current one is.

        <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.8</version>
        </dependency>

To be amended as follows:

            <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.20</version>
              </dependency>
            

Fatal error matching: invalid target distribution: 11

Idea executes Maven command and prompts fatal error matching: invalid target distribution: 11

Environmental Science:

        Project JDK version: 11

        Environment variable JDK version: 1.8

        Maven version: 3.3.9

 
Querying the data, we found that when executing the Maven command, we will find the JDK version of the environment variable, so the JDK version does not match the JDK version of the project

Treatment method

1. Before executing the Maven command, execute the command:

set JAVA_HOME=D:\Java\jdk\adopt-openjdk-11.0.11

After execution, execute the Maven command

2. Modify environment variable Java_ Home, configured as jdk11 directory  

Because most of my projects use JDK1.8, only a few projects use jdk11, so I choose to use the first method  

Maven install error: fatal error matching: error: invalid target distribution: 11.0.8 – > [help 1]

Project scenario:

Maven install: fatal error matching: error: invalid target distribution: 11.0.8 – & gt[ Help 1]

Solution:

Modify settings.xml in Maven directory

<profile> 
​	<id>jdk-11</id>
​	 <activation> 
​			<activeByDefault>true</activeByDefault> 
​			<jdk>11</jdk> 
​	</activation> 
​	<properties> 
​			<maven.compiler.source>11</maven.compiler.source> 		
​			<maven.compiler.target>11</maven.compiler.target> 					<maven.compiler.compilerVersion>11</maven.compiler.compilerVersion> 
​	</properties>
</profile>

https://www.cnblogs.com/zhao1949/p/6180155.html

How to Solve Errors encountered by maven

Could not transfer artifact
org.apache.maven.surefire:surefire-junit-platform:pom:2.22.2 from/to
alimaven (http://maven.aliyun.com/nexus/content/groups/public/):
java.lang.RuntimeException: Unexpected error:
java.security.InvalidAlgorithmParameterException: the trustAnchors
parameter must be non-empty

Solution:

Just load this dependency

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>

Does the version of idea2020.1 import mybayis jar package or report an error? Error: (4,28) Java: package org.apache.ibatis.io does not exist

The other solution is to replace the local warehouse with the Maven warehouse of idea

But I don’t want to change it. I’m afraid there will be any trouble in the future. So I see another solution: using MVN idea:idea Command

In fact, this method can solve the problem that the same kind of package cannot be imported

The solution is as follows:

1. I use terminal of idea directly. Of course, I can also use CMD, but I have to go to the location of the project (directory with POM file) first,

2. Use MVN idea:idea Command:

 
  Finally, build success.

Then there is no error in guiding the package.

Error in publishing project with Maven in idea. Git directory is not found! Please specify a valid

1、 Problem description

1. After using idea development tool and git to download the project, the folder was deleted because of GIT, resulting in problems in Maven packaging
picture display

2、 Solutions

1. Download the GIT project again
2. Retrieve the deleted git folder, which can be