spring-boot创建项目遇到配置问题

今天在创建spring-boot时遇到一个读取不到application.properties的问题,正常是将此文件放在src/main/resouces的子目录下,但是有时候为了方便管理所以需要将位置转移。 如下图所示:

spring-boot创建项目遇到配置问题_第1张图片

此图中我是将文件放在src/main/resouces的propertiesConfig目录下,所以直接运行项目会找不到该文件,此时会报以下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.

所以需要修改sping运行时读取的地址:@PropertySource("classpath:propertiesConfig/Application.properties")加上此注解就可以。此注解是加载application上的


对了,不知道为啥要在application这个类上加上@EnableAutoConfiguration这个注解


你可能感兴趣的:(spring-boot创建项目遇到配置问题)