错误类型提示:
log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection
Caused by: java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection
开始时候的XML文件内容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="url">
<value>jdbc:oracle:thin:@10.0.0.11:1521:orcl</value>
</property>
<property name="username">
<value>scott</value>
</property>
<property name="password">
<value>tiger</value>
</property>
</bean>
<bean id="personDao" class="demo.spring.jdbc.dao.JDBCTemplatePersonDaoImpl">
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
仔细排查后,发现是url错误了,应该为 <value>jdbc:oracle:thin:@localhost:1521:orcl</value>,之后程序正常运行。