Tag Archives: maven

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>

Error reporting of AOP practice in spring

252533rd;381693rd;”

java.lang.NoSuchMethodError: org.springframework.aop.scope.ScopedProxyUtils.isScopedTarget(java/lang/String;)Z

at org.springframework.context.event.EventListenerMethodProcessor.afterSingletonsInstantiated(EventListenerMethodProcessor.java:79)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:781)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.wt.test.AopTest.test1(AopTest.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.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:214)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:210)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:66)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)。

terms of settlement

Upgrade the AOP dependency in POM. It must be above version 4.0

 <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aop</artifactId>
      <version>4.2.2.RELEASE</version>
    </dependency>

Maven executes servlet with error

An error is reported when the servlet executes and the dependency range is not written

add the following code to pom.xml, mainly the dependency range provided

<dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

Error reported: inaccessibleobjectexception

Error message:

Page:

Back end:

java.lang.reflect.InaccessibleObjectException: Unable to make protected java.net.http.HttpRequest() accessible: module java.net.http does not "opens java.net.http" to unnamed module @621f89b8

terms of settlement:

        Change the parameters passed in the controller:   HttpRequest   ——》  HttpServletRequest

(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

How to Solve idea com.baomidou Error

Completely solve the error reported by com.baomidou in idea

Add in pom.xml:

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

Clear all mybatis and mybatis plus related configurations in the YML file and add:

mybatis-plus:
  type-aliases-package: com.peanut.entity
  mapper-locations: classpath:mappers

Select the item and right-click Maven -> Reload project
as shown in the figure, com.baidu no longer turns red:

[Solved] Mailsslsocketfactory error: Cannot find declaration to go to

1. Status. The 1.6.2 jar package is configured in Maven

The solution is to try to add Maven dependency again and replace the invalid jar package version

Finally, create the Lib package manually, copy the downloaded jar package to this directory, and then add it to the library. Add as library is successful

You have 77 PMD violations maven error [How to Solve]

Maven compilation exception

Failed to execute goal org.apache.maven.plugins:
maven-pmd-plugin:3.8:check (default) 
on project xxx: You have 133 PMD violations. 

Reason: PMD verification is added to Maven to judge whether your code complies with the specification. If it does not comply with the specification, an error will be reported when Maven compiles

Solution: how can this specification be removed? Just execute the following command, which can ignore the PMD check

mvn clean install -Dpmd.skip=true -Dcheckstyle.skip=true

Of course, when Maven compiles, there will be unit test execution, so how to ignore unit test execution?Just execute the following command

mvn clean install -Dmaven.test.skip=true

Therefore, as long as you want to ignore it, you can execute a command directly behind it
in a word:

In order to be compatible with errors, the following methods can be performed:

mvn clean install -Dpmd.skip=true -Dcheckstyle.skip=true -Dmaven.test.skip=true

[Solved] java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]

Error Messages:

java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
.......
Caused by:
             org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
......
Caused by:
             java.lang.ClassCastException: class org.springframework.web.SpringServletContainerInitializer cannot be cast to class javax.servlet.ServletContainerInitializer (org.springframework.web.SpringServletContainerInitializer is in unnamed module of loader org.apache.catalina.loader.WebappClassLoader @1e0295e0; javax.servlet.ServletContainerInitializer is in unnamed module of loader org.codehaus.plexus.classworlds.realm.ClassRealm @3d88e6b9)
......

 

cause:
I imported the following dependencies in the project’s pom.xml and found that the tomcat7 plugin can’t run
E.g:

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>4.0.1</version>
</dependency>
<dependency>
  <groupId>javax.servlet.jsp</groupId>
  <artifactId>javax.servlet.jsp-api</artifactId>
  <version>2.3.3</version>
</dependency>

Check:

1. Check whether the current port is occupied by the process

2. Check whether there is a problem with the servlet mapping URL path in web.xml

3. Check for dependency conflicts

reason:

The servlet dependent version imported in the current Maven configuration file is too high and incompatible with tomcat7

Solution:

The tomcat7 plug-in in pom.xml can be upgraded to tomcat8

reference:

<pluginRepositories>
  <pluginRepository>
    <id>alfresco-public</id>
    <url>https://artifacts.alfresco.com/nexus/content/groups/public</url>
  </pluginRepository>
  <pluginRepository>
    <id>alfresco-public-snapshots</id>
    <url>https://artifacts.alfresco.com/nexus/content/groups/public-snapshots</url>
    <snapshots>
      <enabled>true</enabled>
      <updatePolicy>daily</updatePolicy>
    </snapshots>
  </pluginRepository>
  <pluginRepository>
    <id>beardedgeeks-releases</id>
    <url>http://beardedgeeks.googlecode.com/svn/repository/releases</url>
  </pluginRepository>
</pluginRepositories>
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.tomcat.maven</groupId>
      <artifactId>tomcat8-maven-plugin</artifactId>
      <version>3.0-r1655215</version>
      <configuration>
        <port>80</port>
        <path>/</path>
      </configuration>
    </plugin>
  </plugins>
</build>

last:

Refresh the Maven management tool, recompile the Maven project, and then start it with tomcat8!

Springboot Project Error: Failed to execute goal org.apache.maven.plugins

Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.1.0:resources (default-resources) on project heima-leadnews-user: Error loading property file ‘D:\Develop\springboot_ project\heima-leadnews\heima-leadnews-user\maven_ test.properties’

When installing the springboot project, the above errors were compiled. Baidu’s reason is that the Maven version, JDK version and packaging program are occupied. My reason is that the parent project of the project has the following profiles:

<!--<profiles>
        <profile>
            <id>dev</id>
            <build>
                <filters>
                    <filter>maven_dev.properties</filter>
                </filters>
            </build>
        </profile>
        <profile>
            <id>test</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <filters>
                    <filter>maven_test.properties</filter>
                </filters>
            </build>
        </profile>
        <profile>
            <id>prod</id>
            <build>
                <filters>
                    <filter>maven_prod.properties</filter>
                </filters>
            </build>
        </profile>
    </profiles>-->

Because my child project inherits the parent project, but there is no corresponding directory under the child project, the above code in the parent project is cancelled (the specific reason is unknown, learning from the teacher), recompiled and packaged successfully

[Solved] Failed to configure a DataSource: ‘url‘ attribute is not specified…bug

Question page

Error message in log
no mybatis mapper was found in ‘[com. Ego]’ package. Please check your
configuration. Will not attempt to authenticate using SASL (unknown error)

Console output

Solution 1

Solution 1. I read many blogs, most of which are this solution. But it didn’t solve my problem

Solution 2

1. Because the versions of spring web and spring webmvc in POM are inconsistent, unify the dependent versions
2. If there are no database related things configured, comment out the POM dependencies of mybatis and MySQL first

I cited the problem caused by mapper’s Maven dependency in the consumermodel. Just delete it.