SpringBoot project error solution: "Error starting ApplicationContext. To display the conditions report re-run ..."

The SpringBoot project reported an error: Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

80% of the following solutions can help you solve these 'hateful' problems

The error content and screenshots are as follows:

Connected to the target VM, address: '127.0.0.1:4963', transport: 'socket'

  .   ____          _            __ _ _
 / / ___'_ __ _ _(_)_ __  __ _    

( ( )___ | '_ | '| | ' / ` |
/ )| |)| | | | | || (| | ) ) ) )
' || .__|| ||| |, | / / / /
=========||==============|/=///_/
:: Spring Boot :: (v2.3.10.RELEASE)

2021-12-25 14:52:41.578  INFO 13204 --- [           main] m.c.DiitMicrosoftserviceCheckApplication : Starting DiitMicrosoftserviceCheckApplication on old cloud computer with PID 13204 (D:svnworkspace_nxzrbhdztGh_yizhangtudit-check	argetclasses started by liuyundashen in D:svnworkspace_nxzrbhdztGh_yizhangtudit-check)
2021-12-25 14:52:41.583  INFO 13204 --- [           main] m.c.DiitMicrosoftserviceCheckApplication : No active profile set, falling back to default profiles: default
2021-12-25 14:52:43.485  INFO 13204 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-12-25 14:52:43.503  INFO 13204 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-12-25 14:52:43.504  INFO 13204 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.45]
2021-12-25 14:52:43.668  INFO 13204 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-12-25 14:52:43.668  INFO 13204 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1979 ms
2021-12-25 14:52:43.832  INFO 13204 --- [           main] c.a.d.s.b.a.DruidDataSourceAutoConfigure : Init DruidDataSource
2021-12-25 14:52:43.910 ERROR 13204 --- [           main] com.alibaba.druid.pool.DruidDataSource   : testWhileIdle is true, validationQuery not set
2021-12-25 14:52:43.917  INFO 13204 --- [           main] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} inited
 _ _   |_  _ _|_. ___ _ |    _ 
| | |/|_)(_| | |_  |_)||_|_ 
     /               |         
                        3.2.0 
2021-12-25 14:52:44.365  WARN 13204 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cheakRecordController': Unsatisfied dependency expressed through field 'recordService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'TRecordServiceImpl': Unsatisfied dependency expressed through field 'packageService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resultPackageBaseinfoServiceImpl': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'importDB.datasource.url' in value "${importDB.datasource.url}"
2021-12-25 14:52:44.366  INFO 13204 --- [           main] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} closing ...
2021-12-25 14:52:44.368  INFO 13204 --- [           main] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} closed
2021-12-25 14:52:44.372  INFO 13204 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-12-25 14:52:44.391  INFO 13204 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-12-25 14:52:44.410 ERROR 13204 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cheakRecordController': Unsatisfied dependency expressed through field 'recordService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'TRecordServiceImpl': Unsatisfied dependency expressed through field 'packageService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resultPackageBaseinfoServiceImpl': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'importDB.datasource.url' in value "${importDB.datasource.url}"
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:660) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1425) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.14.RELEASE.jar:5.2.14.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.14.RELEASE.jar:5.2.14.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.10.RELEASE.jar:2.3.10.RELEASE]


——When seeing these problems, the log will basically tell you the wrong place, so most of us can analyze the cause of the error according to the information reported in the log:

1. Compilation problems

Look carefully at the reported problem, whether there are words such as: "Description: ...", there is no "description", as shown in the figure above, the operation in this case:
1.clean it up; 2. Then install and recompile it;

3. You can also use this command to recompile

Restart at this time. If the same error is still reported, open the location as shown below to see if there are compiled files, such as mapper.xml file, application.yml or application.properties file, and some configuration files, etc.

--Hey! Angry, I found that there is really no mapper and configuration file here, only the .jar file under main, what should I do?

——Add the location dependencies of the files to be compiled to the pom.xml file, as follows: (This is my file location, you can adjust it according to yours)

<!--Bring in local resources-->
        <resources>
            <!--load lib file, in special cases lib,But most of it depends on the download-->
            <resource>
                <directory>lib</directory>
                <targetPath>BOOT-INF/lib/</targetPath>
                <includes>
                    <include>**/*.jar</include>
                </includes>
            </resource>
            <!--jar package -->
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <!--Compile the properties and xml files -->
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>

OK, clean up -> package -> start -> run successfully, get the job done

Second, the request interface is repeated

According to the log, it can be seen that it says that the path is a problem; so if the interface name you wrote is repeated, there is only one slash or no slash

Screenshot below:

amend as below:

ok, reboot, get the job done

3. Add @Mapper annotation

These situations are the problems described in the description
As shown in the figure:

In this case, to see if it does not scan what it needs, add the @Mapper annotation (to scan the dao layer), or add the @Service annotation (to scan the service layer).

Fourth, add @SpringBootApplication annotation, database problem

According to the problem, it can be seen that springboot will automatically inject the data source and configure jpa when it starts, and solve:
Exclude its injection in @SpringBootApplication
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})

5. Port duplication problem

Check if your running port conflicts, kill it, restart it, or change the port

Here's how to view port conflicts:

  1. window key + R, enter "netstat -aon|findstr 8080" to find the process number occupying port 8080:

    2. Enter "tasklist|findstr "3412" ":

    View the process with process ID "3412":

    3. Enter "taskkill /f /t /im QQ.exe": (/f: mandatory end process)

    end the process

Now you can restart it to see if it runs successfully

6. Package conflict

In other cases, there may be a package conflict. You can clean up your own package in the maven warehouse and download it again.

Hope it can help you

~Thank you for visiting~

at last

I know that most junior and intermediate Java engineers want to improve their skills by exploring their own growth or signing up for classes. However, the tuition fee for training institutions is nearly 10,000 yuan, which is really stressful. The self-learning effect of unsystematic self-learning is inefficient and long, and it is very easy to hit the ceiling and the technology stagnates!

Therefore, I collected and organized a set of "Java Development Complete Learning Materials" for everyone. The original intention is very simple. I hope it can help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.

The editor has encrypted: aHR0cHM6Ly9kb2NzLnFxLmNvbS9kb2MvRFVrVm9aSGxQZUVsTlkwUnc==For security reasons, we have encoded the website through base64, and you can get the website through base64 decoding.

Tags: Java Spring Spring Boot Interview Front-end programming language

Posted by erax on Fri, 09 Sep 2022 01:02:29 +0530