【问题标题】:Issues with Spring Boot + Oracle DatabaseSpring Boot + Oracle 数据库的问题
【发布时间】:2017-12-21 19:17:44
【问题描述】:

我是 Spring boot 的新手,我正在尝试使用 Oracle DB 实现 Spring boot 的示例以用于我的学习目的。请指导我。我不知道我错过了什么。以下是错误,我无法解决。

***************************
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.

我在 POM.xml

中添加了以下依赖项
<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>

下面是 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

这是我的 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> {

}

还有我的控制器类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;
        }

    }

我想我缺少一些配置。请指导。

【问题讨论】:

标签: java spring oracle spring-boot


【解决方案1】:

您的application.properties 必须看起来像

#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

【讨论】:

    猜你喜欢
    • 2021-01-05
    • 2019-04-03
    • 1970-01-01
    • 1970-01-01
    • 2020-12-26
    • 2021-04-05
    • 2020-01-01
    • 2020-05-22
    • 1970-01-01
    相关资源
    最近更新 更多