问答详情
源自:1-3 实体和映射的创建

项目运行起来后找不到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>


提问者:yangwwei 2017-02-15 20:19

个回答

  • 这个昵称已被占用了哦
    2017-07-25 08:29:20

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

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

  • N3verL4nd
    2017-06-16 14:26:06

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


  • kongpanpan
    2017-04-18 13:29:25

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

  • 慕哥7619466
    2017-02-18 13:22:22

    路径没写对