相关疑难解决方法(0)

Spring Boot - 无法确定数据库类型为NONE的嵌入式数据库驱动程序类

这是尝试运行我的Web应用程序时引发的错误:

[INFO] WARNING: Nested in 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]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.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 …
Run Code Online (Sandbox Code Playgroud)

java google-app-engine jpa spring-data spring-boot

202
推荐指数
10
解决办法
37万
查看次数

Spring Boot jdbc数据源自动配置在独立的tomcat上失败

在尝试在独立的tomcat(7)实例上部署和启动Spring启动应用程序时,我们遇到了一个问题,即找不到自动配置的spring数据源bean并抛出相应的异常:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type [javax.sql.DataSource] found for dependency: 
expected at least 1 bean which qualifies as autowire candidate for this dependency. 
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}    at
     org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1060)  at 
    org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:920)   at 
    org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:815)     at 
    org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)   ... 84 more
Run Code Online (Sandbox Code Playgroud)

简单的jdbc spring.datasource在application.properties中正确配置,并且应用程序本身与嵌入式tomcat实例完美地运行,作为独立的spring引导应用程序.

看起来好像无法正确读取和/或处理application.properties文件,或者在数据源自动配置完成之前触发了一些其他bean(例如REST控制器中的服务)的注入.

不使用嵌入式tomcat时是否需要任何额外配置?或者有没有人遇到过类似的问题?

简单的应用和配置:

@EnableAutoConfiguration
@Configuration
@ComponentScan("com.foo")
public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

}
Run Code Online (Sandbox Code Playgroud)

application.properties:

spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase
spring.datasource.username=username
spring.datasource.password=password
spring.datasource.driverClassName=com.mysql.jdbc.Driver
Run Code Online (Sandbox Code Playgroud)

数据源使用示例:

@Repository …
Run Code Online (Sandbox Code Playgroud)

java spring datasource jdbc spring-boot

10
推荐指数
3
解决办法
4万
查看次数