Oracle 11g DBCP网络适配器无法建立连接

Evg*_*rov 2 oracle spring jdbc

我特意将oracle连接到Spring和DBCP.

    <bean id="dataSource" class="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
        <property name="driverClassName" value="oracle.jdbc.OracleDriver" />
        <property name="url" value="jdbc:oracle:thin:@localhost:1521/ORCL" />
        <property name="username" value="PMSYSDB" />
        <property name="password" value="********" />
    </bean>
Run Code Online (Sandbox Code Playgroud)

但我得到: Could not get JDBC Connection; nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (IO Error: The Network Adapter could not establish the connection)

我可以通过SQLDeveloper与这个属性连接:

Hostname: localhost
Port    : 1521
SID     : ORCL
username: PMSYSDB
password:
Run Code Online (Sandbox Code Playgroud)

所以我的数据库启动并运行...防火墙已关闭...数据库和tomcat在同一台机器上...

认为这不重要,但我使用Spring Security的数据源:

     <authentication-manager>
         <authentication-provider>
        <jdbc-user-service data-source-ref="dataSource"

           users-by-username-query="
              select username, password, enabled 
              from users where username=?" 

           authorities-by-username-query="
              select u.username, ur.authority from users u, user_roles ur 
              where u.user_id = ur.user_id and u.username =?  " 

        />
      </authentication-provider>
    </authentication-manager>
Run Code Online (Sandbox Code Playgroud)

Evg*_*rov 5

问题是我将这种语法jdbc:oracle:thin:@localhost:1521/ORCL用于连接字符串.在/Oracle期望服务名称而不是SID(ORCL是我的SID)之后.解决方案是将连接更改为jdbc:oracle:thin:@localhost:1521:ORCL