为了账号安全,请及时绑定邮箱和手机立即绑定

项目运行起来后找不到jdbc.properties文件里面配置的键值对。。。下面是我的配置文件

异常的一部分------------------------------------------------------------------------------

Loading properties file from class path resource [jdbc.properties]

[DEBUG] 2017-02-15 19:09:53 - Adding [localProperties] PropertySource with lowest search precedence

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.driverClass' in [environmentProperties]

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.driverClass' in [servletConfigInitParams]

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.driverClass' in [servletContextInitParams]

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.driverClass' in [jndiProperties]

[DEBUG] 2017-02-15 19:09:53 - Looking up JNDI object with name [java:comp/env/jdbc.driverClass]

[DEBUG] 2017-02-15 19:09:53 - Converted JNDI name [java:comp/env/jdbc.driverClass] not found - trying original name [jdbc.driverClass]. javax.naming.NameNotFoundException: Name [jdbc.driverClass] is not bound in this Context. Unable to find [jdbc.driverClass].

[DEBUG] 2017-02-15 19:09:53 - Looking up JNDI object with name [jdbc.driverClass]

[DEBUG] 2017-02-15 19:09:53 - JNDI lookup for name [jdbc.driverClass] threw NamingException with message: Name [jdbc.driverClass] is not bound in this Context. Unable to find [jdbc.driverClass].. Returning null.

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.driverClass' in [systemProperties]

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.driverClass' in [systemEnvironment]

[DEBUG] 2017-02-15 19:09:53 - Could not find key 'jdbc.driverClass' in any property source. Returning [null]

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.driverClass' in [localProperties]

[DEBUG] 2017-02-15 19:09:53 - Found key 'jdbc.driverClass' in [localProperties] with type [String] and value 'com.mysql.jdbc.Driver'

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.url' in [environmentProperties]

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.url' in [servletConfigInitParams]

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.url' in [servletContextInitParams]

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.url' in [jndiProperties]

[DEBUG] 2017-02-15 19:09:53 - Looking up JNDI object with name [java:comp/env/jdbc.url]

[DEBUG] 2017-02-15 19:09:53 - Converted JNDI name [java:comp/env/jdbc.url] not found - trying original name [jdbc.url]. javax.naming.NameNotFoundException: Name [jdbc.url] is not bound in this Context. Unable to find [jdbc.url].

[DEBUG] 2017-02-15 19:09:53 - Looking up JNDI object with name [jdbc.url]

[DEBUG] 2017-02-15 19:09:53 - JNDI lookup for name [jdbc.url] threw NamingException with message: Name [jdbc.url] is not bound in this Context. Unable to find [jdbc.url].. Returning null.

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.url' in [systemProperties]

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.url' in [systemEnvironment]

[DEBUG] 2017-02-15 19:09:53 - Could not find key 'jdbc.url' in any property source. Returning [null]

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.url' in [localProperties]

[DEBUG] 2017-02-15 19:09:53 - Found key 'jdbc.url' in [localProperties] with type [String] and value 'jdbc:mysql://localhost:3306/ssh_employee'

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.username' in [environmentProperties]

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.username' in [servletConfigInitParams]

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.username' in [servletContextInitParams]

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.username' in [jndiProperties]

[DEBUG] 2017-02-15 19:09:53 - Looking up JNDI object with name [java:comp/env/jdbc.username]

[DEBUG] 2017-02-15 19:09:53 - Converted JNDI name [java:comp/env/jdbc.username] not found - trying original name [jdbc.username]. javax.naming.NameNotFoundException: Name [jdbc.username] is not bound in this Context. Unable to find [jdbc.username].

[DEBUG] 2017-02-15 19:09:53 - Looking up JNDI object with name [jdbc.username]

[DEBUG] 2017-02-15 19:09:53 - JNDI lookup for name [jdbc.username] threw NamingException with message: Name [jdbc.username] is not bound in this Context. Unable to find [jdbc.username].. Returning null.

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.username' in [systemProperties]

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.username' in [systemEnvironment]

[DEBUG] 2017-02-15 19:09:53 - Could not find key 'jdbc.username' in any property source. Returning [null]

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.username' in [localProperties]

[DEBUG] 2017-02-15 19:09:53 - Found key 'jdbc.username' in [localProperties] with type [String] and value 'root'

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.password' in [environmentProperties]

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.password' in [servletConfigInitParams]

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.password' in [servletContextInitParams]

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.password' in [jndiProperties]

[DEBUG] 2017-02-15 19:09:53 - Looking up JNDI object with name [java:comp/env/jdbc.password]

[DEBUG] 2017-02-15 19:09:53 - Converted JNDI name [java:comp/env/jdbc.password] not found - trying original name [jdbc.password]. javax.naming.NameNotFoundException: Name [jdbc.password] is not bound in this Context. Unable to find [jdbc.password].

[DEBUG] 2017-02-15 19:09:53 - Looking up JNDI object with name [jdbc.password]

[DEBUG] 2017-02-15 19:09:53 - JNDI lookup for name [jdbc.password] threw NamingException with message: Name [jdbc.password] is not bound in this Context. Unable to find [jdbc.password].. Returning null.

[DEBUG] 2017-02-15 19:09:53 - Searching for key 'jdbc.password' in [systemProperties]

jdbc.properties----------------------------------------------------------------------------------

jdbc.driverClass=com.mysql.jdbc.Driver

jdbc.url=jdbc:mysql://localhost:3306/ssh_employee

jdbc.username=root

jdbc.password=root

applicationContext.xml部分--------------------------------------------------------------------

<!-- 引入外部属性文件 -->

<context:property-placeholder location="classpath:jdbc.properties"/>

<!-- 配置连接池 -->

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">

<property name="driverClass" value="${jdbc.driverClass}"></property>

<property name="jdbcUrl" value="${jdbc.url}"></property>

<property name="user" value="${jdbc.username}"></property>

<property name="password" value="${jdbc.password}"></property>

</bean>

web.xml部分-----------------------------------------------------------------------------

<listener>

    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

<context-param>

    <param-name>contextConfigLocation</param-name>

    <param-value>classpath:applicationContext.xml</param-value>

</context-param>


正在回答

4 回答

http://blog.csdn.net/superdog007/article/details/48022983

参考这个,我改了之后有效果。

0 回复 有任何疑惑可以回复我~

<context:property-placeholder location="classpath:jdbc.properties" ignore-unresolvable="true"/>


1 回复 有任何疑惑可以回复我~

bean里面配置的属性property的name要与class类里面的属性名字一致

0 回复 有任何疑惑可以回复我~

路径没写对

0 回复 有任何疑惑可以回复我~
#1

慕粉3798235

我也出现了这种问题,路径该怎样显示呢,一直不明白
2017-03-05 回复 有任何疑惑可以回复我~
#2

慕哥7619466

首先你确定你的jdbc.properties是不是在classpath下面放着,
2017-04-26 回复 有任何疑惑可以回复我~
#3

慕哥7619466 回复 慕粉3798235

首先你确定你的jdbc.properties是不是在classpath下面放着,
2017-04-26 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

项目运行起来后找不到jdbc.properties文件里面配置的键值对。。。下面是我的配置文件

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信