spring boot下非web应用,mysql数据源报错问题
2017-10-26 16:21
375 查看
在非web应用下,spring boot启动时提示如下错误:
spring boot启动时默认会自动配置数据源为org.apache.tomcat.jdbc.pool.DataSource。即使在配置文件或代码中指定了其他的数据源(如druid)。
解决方法是:在@SpringBootApplication注解中取消自动配置,如下:
另外,pom.xml中加入依赖:
有时会出现ClassNotFoundException: com.mysql.jdbc.Driver。并且在IDEA Project Structure ->Modules ->Dependencies中有Maven:mysql:mysql-connector-java:unknown项。
解决在pom.xml指定mysql-connector-java的版本即可
org.springframework.context.annotation.AnnotationConfigApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
spring boot启动时默认会自动配置数据源为org.apache.tomcat.jdbc.pool.DataSource。即使在配置文件或代码中指定了其他的数据源(如druid)。
解决方法是:在@SpringBootApplication注解中取消自动配置,如下:
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) public class ThisApplication { public static void main( String[] args ) { SpringApplication.run(ThisApplication.class); } }
另外,pom.xml中加入依赖:
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency>
有时会出现ClassNotFoundException: com.mysql.jdbc.Driver。并且在IDEA Project Structure ->Modules ->Dependencies中有Maven:mysql:mysql-connector-java:unknown项。
解决在pom.xml指定mysql-connector-java的版本即可
相关文章推荐
- 解决mysql和可视化工具Navicat与web应用中数据库传输中文乱码问题
- XMLHTTP和DOMDocument在WEB应用上的使用问题(二)
- Web应用中的中文乱码问题
- .NET的WEB商业应用架构所要解决的若干问题
- 疑难杂症:解决由早期版本的Web应用项目模板造成的VS 2005 SP1 Beta的问题
- Asp.net中处理一个站点不同Web应用共享Session的问题
- Web应用中重复提交的问题的三种解决方案
- Web应用中重复提交的问题的三种解决方案
- 常见Web应用安全问题(1 - 4)(一)
- Web应用中重复提交的问题的三种解决方案
- 关于使用MySQL的ODBC驱动建立数据源出错的问题
- 在NHibernate中应用Mysql正为空日期的问题困扰
- 疑难杂症:解决由早期版本的Web应用项目模板造成的VS 2005 SP1 Beta的问题
- [原创] Java WebApp 中的 MySql 中文乱码问题
- Asp.net中处理一个站点不同Web应用共享Session的问题
- Web应用中的中文问题
- 将 Java Web 应用从 Windows 移植到 AIX 时需要注意的问题
- XMLHTTP和DOMDocument在WEB应用上的使用问题
- 发布Sharepoint网站和扩展WEB应用时碰到的问题
- XMLHTTP和DOMDocument在WEB应用上的使用问题