springboot error

(1) maven.plugins:maven-compiler-plugin:3.8.0:compile failed missing: org/objectweb/asm/ClassVisitor

在使用 springboot 2.1.3 后,开始出现这个问题

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project model: Execution default-compile of goal org.apache.
maven.plugins:maven-compiler-plugin:3.8.0:compile failed: Unable to load the mojo 'compile' in the plugin 'org.apache.maven.plugins:maven-compiler-plugin:3.8.0'. A required class is
missing: org/objectweb/asm/ClassVisitor
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @  ---
[WARNING] Error injecting: org.apache.maven.plugin.compiler.CompilerMojo
com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error injecting constructor, java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
  at org.codehaus.plexus.languages.java.jpms.LocationManager.<init>(Unknown Source)

maven-compiler-plugin 版本问题,指定版本

方法一,在pluginManagement指定

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

方法二,在每个模块里手动指定

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <classifier>exec</classifier>
            </configuration>
        </plugin>
    </plugins>
</build>

(2) java.lang.IllegalStateException: Ambiguous mapping. Cannot map ‘basicErrorController’ method

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-06-16 18:42:26.409 ERROR 16924 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'basicErrorController' method 
public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
to { /error}: There is already 'indexController' bean method
public java.lang.String edu.controller.IndexController.error() mapped.
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1762) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
	...
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.1.3.RELEASE.jar:2.1.3.RELEASE]
Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'basicErrorController' method 
public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
to { /error}: There is already 'indexController' bean method
public java.lang.String edu.controller.IndexController.error() mapped.
	at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.assertUniqueMethodMapping(AbstractHandlerMethodMapping.java:618) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    ...
	... 21 common frames omitted
  1. 少jar包,少 asm-commons-3.3.jar asm-3.3.jar asm-tree-3.3.jar 这几个jar包,对应pom如下。
  2. 可能是版本问题,换个低版本就不报错了。
  3. forceupdate 更新jar包, 或者删除完整的.m2本地存储库(笨办法)
<dependencies>
    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
    </dependency>
</dependencies>

<!-- https://mvnrepository.com/artifact/asm/asm -->
<dependency>
  <groupId>asm</groupId>
  <artifactId>asm</artifactId>
  <version>3.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/asm/asm-commons -->
<dependency>
  <groupId>asm</groupId>
  <artifactId>asm-commons</artifactId>
  <version>3.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/asm/asm-tree -->
<dependency>
  <groupId>asm</groupId>
  <artifactId>asm-tree</artifactId>
  <version>3.3.1</version>
</dependency>

(3) This application has no explicit mapping for /error, so you are seeing this as a fallback.

This application has no explicit mapping for /error, so you are seeing this as a fallback.

There was an unexpected error (type=Not Found, status=404).
No message available
  1. Controller里是不是忘记加 @Conterller 注解了
  2. 路径不对

(4) java.net.SocketException: Permission denied

2019-06-17 16:41:37.898 [main] ERROR [o.s.b.diagnostics.LoggingFailureAnalysisReporter] [42] - 

***************************
APPLICATION FAILED TO START
***************************

Description:

The Tomcat connector configured to listen on port 80 failed to start. The port may already be in use or the connector may be misconfigured.

Action:

Verify the connector's configuration, identify and stop any process that's listening on port 80, or configure this application to listen on another port.

2019-06-17 16:41:37.899 [main] INFO  [o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext] [989] - Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@27ddd392: startup date [Mon Jun 17 16:41:32 CST 2019]; root of context hierarchy
2019-06-17 16:41:37.900 [main] INFO  [o.s.jmx.export.annotation.AnnotationMBeanExporter] [452] - Unregistering JMX-exposed beans on shutdown

1、端口被占用
2、没有对应权限

(5) Circular placeholder reference ‘’ in property definitions

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.alibaba.druid.pool.DruidDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalArgumentException: Circular placeholder reference 'jdbc_url' in property definitions

Caused by: java.lang.IllegalArgumentException: Circular placeholder reference 'jdbc_url' in property definitions
	

application.properties 里和 application-dev.properties 里的变量名一样,提示Circular placeholder reference ‘’ in property definitions

升级到 springboot v2.1.3.RELEASE 后出现这个问题

有两个办法

1、springboot 新版推荐使用 @jdbc_url@ 替代 ${jdbc_url}
修改前 jdbc_url=${jdbc_url}
修改后 jdbc_url=@jdbc_url@

2、变量用不一样的名字
修改前 jdbc_url=${jdbc_url}
修改后 jdbc_url=${url}

启动报错(Circular placeholder reference)
使用SpringBoot1.4.0的一个坑
Maven resource filtering not working - because of spring boot dependency duplicate

(6) Failed to create assembly:Error creating assembly archive asm: Problem creating zip:Execution exception

Failed to execute goalorg.apache.maven.plugins:maven-assembly-plugin:2.5.5:single(make-assembly) on project web: Failed to create assembly:Error creating assembly archive asm: Problem creating zip:Execution exception (and the archive is probably corrupt but Icould not delete it): Java heap space -> [Help 1] 

原因:maven编译时内存溢出导致 Java heap space

解决办法:
1、使用自己安装的maven
2、配置IDEA里Maven的配置
Settings -> Build,Execution,Deployment -> Build Tools -> Maven -> Importing VM options for importer -Xmx2048m
3、JDK版本设置高一点

Problem creating zip: Execution exce ption (and the archive is probably corrupt but I could not delete it): Java heap space

(7) Field in required a bean of type ‘’ that could not be found.

Field  in   required a bean of type '' that could not be found.

The injection point has the following annotations:
	- @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.jdcar.wx.dao.dataserver.CarBrandSeriesDao' in your configuration.
  1. 查看 scanBasePackge 配置是否正确,springboot默认只扫描配置包下的
  2. 查看 dao层 配置是否正确
  3. 查看 数据库 配置是否正确
  4. 查看 是否加了 @Autowired

springboot 启动报错:required a bean of type ‘’ that could not be found

(8) Class path contains multiple SLF4J bindings.

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/export/App/lib/log4j-slf4j-impl-2.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/export/App/lib/slf4j-log4j12-1.7.24.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/agent/jmonitor/jmonitor/../lib/jmonitor-core.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/export/App/lib/log4j-slf4j-impl-2.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/export/App/lib/slf4j-log4j12-1.7.24.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]

用maven找到对应jar,exclusion 对应依赖

<exclusion>
    <artifactId>slf4j-log4j12</artifactId>
    <groupId>org.slf4j</groupId>
</exclusion>

(9) log4j:WARN No appenders could be found for logger (org.springframework.data.repository.config.RepositoryConfigurationDelegate).

log4j:WARN No appenders could be found for logger (org.springframework.data.repository.config.RepositoryConfigurationDelegate).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

(10) log4j:WARN No appenders could be found for logger (com.alibaba.druid.pool.DruidDataSource).

log4j:WARN No appenders could be found for logger (com.alibaba.druid.pool.DruidDataSource).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

http://logging.apache.org/log4j/1.2/faq.html#noconfig

(11) An attempt was made to call the method javax.servlet.ServletContext.getClassLoader()Ljava/lang/ClassLoader; but it does not exist. Its class, javax.servlet.ServletContext, is available from the following locations

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-02-21 20:51:18.989 ERROR[main]o.s.b.d.LoggingFailureAnalysisReporter.report|

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call the method javax.servlet.ServletContext.getClassLoader()Ljava/lang/ClassLoader; but it does not exist. Its class, javax.servlet.ServletContext, is available from the following locations:

    jar:file:/export/App/lib/servlet-api-2.5-6.1.14.jar!/javax/servlet/ServletContext.class
    jar:file:/export/App/lib/javax.servlet-api-4.0.1.jar!/javax/servlet/ServletContext.class

It was loaded from the following location:

    file:/export/App/lib/servlet-api-2.5-6.1.14.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContext

记一次jar包冲突导致项目启动失败的处理过程【java.lang.NoSuchMethodError:javax.servlet.ServletContext】

有2个jar包有 javax/servlet/ServletContext.class 类,去掉一个低版本的。

<exclusion>
    <artifactId>servlet-api-2.5</artifactId>
    <groupId>org.mortbay.jetty</groupId>
</exclusion>

(11) java.lang.ClassNotFoundException: javax.servlet.annotation.WebServlet

2020-02-21 21:59:26.787 ERROR [main] org.springframework.boot.SpringApplication.reportFailure | Application run failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servletComponentRegisteringPostProcessor': Bean instantiation via constructor failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/annotation/WebServlet

Caused by: java.lang.NoClassDefFoundError: javax/servlet/annotation/WebServlet

Caused by: java.lang.ClassNotFoundException: javax.servlet.annotation.WebServlet

添加jar包

<dependency>
    <artifactId>javax.servlet-api</artifactId>
    <groupId>javax.servlet</groupId>
</dependency>

(12) A bean with that name has already been defined in file

2020-03-11 14:13:38.753 ERROR [main] org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter.report | 

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'xxxImpl', defined in class path resource [spring-xxx-provider.xml], could not be registered. A bean with that name has already been defined in file [xxxImpl.class] and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
 

application.properties 文件里配置 spring.main.allow-bean-definition-overriding=true 后解决

Springboot高版本启动报错。需增加配置信息

References

[1] 启动报错(Circular placeholder reference)
[2] 使用SpringBoot1.4.0的一个坑
[3] Maven resource filtering not working - because of spring boot dependency duplicate
[4] Problem creating zip: Execution exce ption (and the archive is probably corrupt but I could not delete it): Java heap space
[5] springboot 启动报错:required a bean of type ‘’ that could not be found
[6] Springboot高版本启动报错。需增加配置信息