Spring引导oracle连接指定的Oracle URL无效:OracleDataSource.makeURL

时间:2018-04-14 07:35:49

标签: spring oracle spring-boot spring-data-jpa

在尝试连接到oracle数据库的春季启动应用程序中,我得到以下异常

    java.sql.SQLException: Invalid Oracle URL specified: OracleDataSource.makeURL
    at oracle.jdbc.pool.OracleDataSource.makeURL(OracleDataSource.java:1536)
    at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:214)
    at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:184)
    at com.pravaa.apex.MainController.getEmployees(MainController.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

我的属性文件如下:

    #Oracle connection
    oracle.username=a_test_erd
    oracle.password=somepassword
    oracle.url=jdbc:oracle:thin:@abc.def.com:1521:XE

我的配置类如下:

import java.sql.SQLException;

import javax.sql.DataSource;
import javax.validation.constraints.NotNull;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import oracle.jdbc.pool.OracleDataSource;

@Configuration
@ConfigurationProperties("oracle")
public class OracleConfiguration {
    @NotNull
    private String username;

    @NotNull
    private String password;

    @NotNull
    private String url;

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    @Bean
    DataSource dataSource() throws SQLException {
        OracleDataSource dataSource = new OracleDataSource();
        dataSource.setUser(username);
        dataSource.setPassword(password);
        dataSource.setURL(url);
        dataSource.setImplicitCachingEnabled(true);
        dataSource.setFastConnectionFailoverEnabled(true);
        return dataSource;
    }
}

我尝试了此处提供的解决方案Invalid Oracle URL specified: OracleDataSource.makeURL以及其他一些帖子。还是有同样的问题。有人可以帮忙。

1 个答案:

答案 0 :(得分:1)

看起来你错过了#34; //"在你的数据库url之后。试试

breaks