简体   繁体   中英

class path resource [target/jdbc.properties] cannot be opened because it does not exist

I am making a simple spring application. I already programed this on my other computer and decided to do it again from scratch to really commit it into memory. However my properties file for some reason is not in the class path. I right clicked the properties file and selected "copy qualified name" in eclipse to get the files path. However it is saying the file does not exsist and I find this very weird because I looked at my working example and it is in the same folder "target" and works fine.

When I click "copy qualified name" I get /DatabaseSpringframework/target/jdbc.properties I took away /DatabaseSpringframework/ and left the target/jdbc.properties and still the same error. Here is my xml file...

<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans   
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context    
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd">

<context:component-scan base-package="com.learntoprogram"></context:component-
scan>
<context:property-placeholder location="target/jdbc.properties" />


<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="username" value="${jdbc.username}"></property>
    <property name="url" value="${jdbc.url}"></property>
    <property name="driverClassName" value="${jdbc.driver}"></property>
</bean>


<tx:annotation-driven />
<bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
</bean>
</beans>

Change location="target/jdbc.properties" to location="classpath:jdbc.properties" . That finds the property file in the classpath.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM