Failed to configure a DataSource: ‘url’ attribute is not specified and no embedde
问题描述:
启动新的spring boot项目时,提示Failed to configure a DataSource: ‘url’ attribute is not specified and no embedde。其中配置的数据库的url,username和password都是正确的,但是后台一直显示报这个错。后来发现application.yml 中没有显示为资源文件的表示其中配置的数据库的url,username和password都是正确的,但是后台一直显示报这个错。后来发现application.yml 中没有显示为资源文件的标识,导致系统没有识别出yml文件。
解决:
pom文件中build 中加上如下代码,将配置文件打到jar中
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
application文件继承SpringBootServletInitializer探究
一般来说spring boot 项目可以直接运行Application文件的main方法,运行在内置的tomcat中。继承SpringBootServletInitializer 类,并重写configure方法可以让项目运行在外置的tomcat容器中(当然你还需要在pom文件中指定打包方式为war),实例代码如下。
public static void main(String[] args) {
SpringApplication app = new SpringApplication(DemoApplication.class);
app.run(args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DemoApplication.class);
}
yml文件data-username && username大乌龙
问题描述:
之前在yml文件填写用 data-username,data-password来填写数据库的用户名密码时,一直提示需要密码,密码不正确,后来才发现,应该是username和password
解决
将 data-username替换成username,data-password替换成password后,正常。