报错问题
关键信息:Description: Failed to auto-configure a DataSource: ‘spring.datasource.url’ is not
specified and no embedded datasource could be auto-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)
原因分析
解决方案
- 方法一(启动时加载本不需要加载的数据源)
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class SpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(MySpringBootApplication.class,args);
}
}
- 方法二(有数据源依旧报错,配置文件没有加载成功)
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>*</include>
<include>*/*</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<testIncludes>
<testInclude>none</testInclude>
</testIncludes>
<compilerArguments>
<extdirs>${project.basedir}/src/main/webapp/WEB-INF/lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>