2016-12-10 184 views
2

我無法使用JPA在春季啓動訪問MySQL在春季啓動無法訪問MySQL

我是新的春季引導和春季。

我得到了誤差小於

Description: 

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 
Action: 
Consider revisiting the conditions above or defining a bean of type 'javax.sql.DataSource' in your configuration. 

我application.properties文件有如下行

spring.datasource.driver-class-name=com.mysql.jdbc.Driver 
spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase 
spring.datasource.username=root 
spring.datasource.password=mypassword 
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect 
spring.jpa.show-sql=true 
spring.jpa.hibernate.ddl-auto=update 

的錯誤是我能想到的是春天啓動的抱怨,我沒有」看t set(spring.datasource.jndi-name)屬性.....我認爲這是不必要的,因爲我已經給出登錄憑據的數據源url &。

我不知道我應該給spring.datasource.jndi-name

我很感激任何幫助。我對此感到震驚。

+0

顯示你的'pom.xml',你的類路徑中是否有MySQL驅動程序? – Artegon

+0

這非常有趣。你能夠在某個地方分享樣本,我想了解爲什麼其他條件不在此處列出。 –

+0

感謝您的回覆。 –

回答

0

與嘗試:

spring.datasource.driver-class-name=com.mysql.jdbc.jdbc2.optional.MysqlDataSource 
spring.datasource.name= 

與空數據源名稱和上面的司機,再加上你的其他屬性。

+0

感謝您的回覆,我已將我的maven設置搞亂了。我試圖卸載沒有工作的mysql&spring工具套件。 **最後我嘗試從我的主目錄中刪除.m2文件夾**,它對我有用。 –

0

在應用程序開發的開頭我已經加入到主類:

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) 

我沒曾想已配置我的數據庫。 然後我就忘記了這一點。刪除此行後,上述錯誤消失。