Oracle data-source configuration for Spring

前端 未结 4 1499
一向
一向 2020-12-28 17:07

In the Spring framework, how is an Oracle data-source configured?

相关标签:
4条回答
  • 2020-12-28 17:35

    In the context.xml file:

    <bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
        <property name="dataSourceName" value="ds"/>
        <property name="URL" value="jdbc:oracle:thin:@<hostname>:<port_num>:<SID>"/>
        <property name="user" value="dummy_user"/>
        <property name="password" value="dummy_pwd"/>
    </bean>
    

    Example of URL: jdbc:oracle:thin:@abc.def.ghi.com:1234:TEAM4

    0 讨论(0)
  • 2020-12-28 17:40
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="dataSourceName" value="oracle.jdbc.driver.OracleDriver" />
        <property name="URL" value="jdbc:oracle:thin:@localhost:1521:XE" />
        <property name="username" value="hr" />
        <property name="password" value="hr" />
        <property name="initialSize" value="1" />
        <property name="maxActive" value="5" />
    </bean>
    
    0 讨论(0)
  • 2020-12-28 17:41

    Note you may want to add to the above that the Oracle driver does not have an open source licence so it will not be in the Maven central repository. You'll have to add it to your local repo.

    To do this: Get the driver you want from: http://www.oracle.com/

    Or you can get it from your oracle installation: {ORACLE_HOME}\jdbc\lib\ojdbc6.jar

    Then run the following maven command:

    mvn install:install-file -Dfile={Path/to/your/ojdbc.jar} -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar
    

    This should install it in your local repository so when you reference it as user640378 states above it should work correctly.

    0 讨论(0)
  • 2020-12-28 17:46

    1. Since Oracle JDBC Driver is not in Maven repository, download it from http://www.oracle.com/technetwork/database/features/jdbc/default-2280470.html (for example Oracle Database 12.1.0.2 JDBC Driver) and add this driver through Maven command as follows:

    (in my case)

    mvn install:install-file -Dfile=D:\Downloads\Java\ojdbc7.jar -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.2 -Dpackaging=jar
    

    2. Add in pom.xml

     <dependency>
         <groupId>com.oracle</groupId>
         <artifactId>ojdbc7</artifactId>
         <version>12.1.0.2</version>
     </dependency>
    

    3. Add in application.properties file

    spring.datasource.url=jdbc:oracle:thin:@localhost:1521:xe
    spring.datasource.username=hr
    spring.datasource.password=hr
    spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
    
    0 讨论(0)
提交回复
热议问题