Tag Archives: Spring boot startup error

[Solved] Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource

Springboot does not specify the “url” property, and cannot configure an embedded data source. Cause: Unable to determine the appropriate driver class

When you open a new springboot project:

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
    If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
    If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

First, check whether the yml data source configuration file is correct, account password, etc…

I found that there is no resource file in the target file. A closer look shows that there is no icon in the resource file.

Solution:

Step 1: Select the corresponding item and right-click: Open Module Settings

Step 2: Click in sequence according to the corresponding steps, and finally don’t forget to Apply

If other startup errors fail, you can leave a comment!

[Solved] spring boot Startup Error: Error creating bean with name ‘requestMappingHandlerMapping‘ defined in class path

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 'reachIndex' method 
com.xxx.controller.ReachIndex#getxxindex(Model, String)
to { [/xxindex]}: There is already 'indexController' bean method
com..controller.IndexController#getxxindex(Model, String) mapped.
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:338)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332)
	at com.xxx.Application.main(Application.java:15)
	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)
Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'reachIndex' method 
com.xxx.controller.ReachIndex#getxxindex(Model, String)
to { [/xxindex]}: There is already 'indexController' bean method
com.xxx.controller.IndexController#getxxindex(Model, String) mapped.
	at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.validateMethodMapping(AbstractHandlerMethodMapping.java:665)
	at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.register(AbstractHandlerMethodMapping.java:631)
	at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod(AbstractHandlerMethodMapping.java:328)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod(RequestMappingHandlerMapping.java:395)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod(RequestMappingHandlerMapping.java:76)
	at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lambda$detectHandlerMethods$2(AbstractHandlerMethodMapping.java:298)
	at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
	at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.detectHandlerMethods(AbstractHandlerMethodMapping.java:296)
	at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.processCandidateBean(AbstractHandlerMethodMapping.java:265)
	at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:224)
	at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:212)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:206)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1845)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1782)
	... 21 common frames omitted

Question:
Mainly the controller layer appears with two same url: @RequestMapping(“/xxxx”);
Solution:
Comment out one of them, or modify the mapping address inside the brackets of one of the @RequestMapping(“/xxxx”).

[Solved] Spring Boot Startup Error: Failed to load property source from location ‘classpath:/application-dev.yml‘

Application.yml file format problem

If your project has no configuration errors and the configuration file name is normal, and you still have this problem, it must be a problem with the encoding of your yml file.

Because the encoding format of this file is GBK, the encoding format of the project is UTF-8, there are comments in it, and the comments are garbled, which leads to compilation failure.

Solution:

IDEA open path: File –> Settings –> File Encodings, then change the format of /application.yml to the same as the project, i.e.: UTF-8.
To be on the safe side, change “Project Encoding” to UTF-8 as well.
Restart IDEA, then start the project, OK.

Translated with www.DeepL.com/Translator (free version)

[How to Fix] Spring boot startup error: could not resolve placeholder

When starting the whole spring boot project, an error occurred:
could not resolve placeholder

Reason: the configuration file is not specified, because there are multiple configuration files under Src/main/resources, such as application- dev.properties , boss.properties And so on.

Solution:
method 1:
in application.properties Join in

spring.profiles.active= @env@

Used to automatically decide which profile to choose.

Method 2: (not a good method)

@Configuration
@EnableTransactionManagement
// Added by yourself, specifying the configuration file
@PropertySource(value = "classpath:application-dev.properties", ignoreResourceNotFound = true)
public class DruidDBConfig {

    private static final Logger LOG = LoggerFactory.getLogger(DruidDBConfig.class);

    @Value("${spring.datasource.url}")
    private String dbUrl;

    @Value("${spring.datasource.username}")
    private String username;
    。。。
}