2017-12-21 2 views
-1

Ich bin neu zu Spring-Boot und versuchen, ein Beispiel für Spring-Boot mit Oracle DB für meinen Lernzweck zu implementieren.Kindly führen mich. Ich weiß nicht, was ich vermisse. Unten ist der Fehler und ich kann es nicht lösen.Probleme mit Spring Boot + Oracle-Datenbank

*************************** 
APPLICATION FAILED TO START 
*************************** 

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. 

Ich habe die unten Abhängigkeiten in pom.xml hinzugefügt

<dependencies>   
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-jpa</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-jdbc</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-jersey</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-security</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-validation</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web-services</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-tomcat</artifactId> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.oracle</groupId> 
     <artifactId>ojdbc14</artifactId> 
     <version>10.2.0.4.0</version> 
    </dependency> 
</dependencies> 

Im Folgenden finden Sie die application.properties

#Tomcat Server Properties 
server.port = 8099 

#Oracle Database Properties 
oracle.username=xxxxx 
oracle.password=xxxxx 
oracle.url=jdbc:oracle:thin:@localhost:1521:XE 
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver 

#Hibernate Properties 
spring.jpa.database-platform=org.hibernate.dialect.OracleDialect 

Das ist mein SpringBootLearningApplication.java

package com.learning.springboot.main; 

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 
import org.springframework.context.annotation.ComponentScan; 

@SpringBootApplication 
@ComponentScan(basePackages = "com.learning.springboot") 
@EnableAutoConfiguration(exclude=DataSourceAutoConfiguration.class) 
public class SpringBootLearningApplication { 

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

UserRepository.java

package com.learning.springboot.dao; 

import org.springframework.data.repository.CrudRepository; 
import org.springframework.stereotype.Repository; 

import com.learning.springboot.entity.User; 

@Repository 
public interface UserRepository extends CrudRepository<User, String> { 

} 

Und meine Controller-Klasse TestController.java

package com.learning.springboot.controller; 

import java.util.ArrayList; 
import java.util.List; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.web.bind.annotation.GetMapping; 
import org.springframework.web.bind.annotation.RestController; 

import com.learning.springboot.dao.UserRepository; 
import com.learning.springboot.entity.User; 

    @RestController 
    public class TestController { 

     @Autowired 
     UserRepository userRepository; 

     @GetMapping("/welcome") 
     public List<User> displayWelcomeMessage() { 

      List<User> list = new ArrayList<>(); 
      userRepository.findAll().forEach(list::add); 
      return list; 
     } 

    } 

Ich glaube, ich einige Konfigurationen fehle. Freundliche Anleitung.

+0

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-connect-to-production-database –

Antwort

0

Ihre application.properties muss aussehen wie

#Tomcat Server Properties 
server.port = 8099 

#Oracle Database Properties 
spring.datasource.username=xxxxx 
spring.datasource.password=xxxxx 
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:XE