2017-06-18 302 views
0

休眠獲取下面的錯誤使用Hibernate配置如何配置彈簧引導

Parameter 0 of constructor in org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration required a bean of type 'javax.sql.DataSource' that could not be found. 
    - Bean method 'dataSource' not loaded because @ConditionalOnProperty (spring.datasource.jndi-name) did not find property 'jndi-name' 
    - Bean method 'dataSource' not loaded because @ConditionalOnBean (types: org.springframework.boot.jta.XADataSourceWrapper; SearchStrategy: all) did not find any beans 

操作:

考慮重新審視上述條件或定義類型的豆「的javax.sql.DataSource」你組態。

這是我使用

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration; 
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; 
@SpringBootApplication 
@EnableAutoConfiguration(exclude={ DataSourceAutoConfiguration.class, 
     DataSourceTransactionManagerAutoConfiguration.class,JpaRepositoriesAutoConfiguration.class}) 
public class Application { 
    public static void main(String[] args) throws Throwable { 

     SpringApplication.run(Application.class, args); 
    } 
} 

屬性文件中的Application.java文件 -

spring.jpa.hibernate.ddl-auto=create-drop 
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:ORCL 
spring.datasource.username=system 
spring.datasource.password=**** 
spring.datasource.driver-class-oracle.jdbc.driver.OracleDriver 
spring.datasource.testWhileIdle = true 
spring.datasource.validationQuery = SELECT 1 

spring.jpa.show-sql = true 
spring.jpa.hibernate.ddl-auto = update 
spring.jpa.hibernate.naming-strategy = 
org.hibernate.cfg.ImprovedNamingStrategy 
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect 

回答

4

已經排除了DataSourceAutoConfiguration這意味着你必須手動指定@BeanDataSource。由於排除,application.properties中的數據源配置將不會被加載。

+0

我試圖通過從排除中刪除,但仍然得到相同的錯誤。我是否需要爲此默認指定DataSource? – user3199286