spring 3.0 后提供了注解配置引入,<context:property-placeholder/>,方便。但是往往第一次使用時(shí)會(huì )遇到此屬性配置進(jìn)applicationContext.xml文件中,會(huì )出現紅叉:
“The prefix "context" for element "context:property-placeholder" isnot bound. ”
只需要在文件頭中引入:xmlns:context="http://www.springframework.org/schema/context"即可。
舉例如下:
<?xml version="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"destroy-method="close">
<property name="driverClass"value="${jdbc.driverClassName}"/>
<property name="jdbcUrl"value="${jdbc.url}"/>
<property name="user"value="${jdbc.username}"/>
<property name="password"value="${jdbc.password}"/>
</bean>
<context:property-placeholderlocation="classpath:jdbc.properties"/>
</beans>
jdbc.properties:
#jdbc配置
jdbc.driverClassName = oracle.jdbc.driver.OracleDriver
jdbc.url = jdbc:oracle:thin:@//localhost:1521/orcl
jdbc.username = scotter
jdbc.password = 123
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請
點(diǎn)擊舉報。