spring 中的config.perporties文件怎么加载不到

米扬 发布于 2012/07/28 14:03
阅读 2K+
收藏 0

这个问题纠结了我还几天了 那问高人指点一下 谢谢

spring配置:

<?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-2.5.xsd

    http://www.springframework.org/schema/tx

    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd

    http://www.springframework.org/schema/context

    http://www.springframework.org/schema/context/spring-context-2.5.xsd">

 

    <context:annotation-config/>

    <context:component-scan base-package="com.chat"/>

 

    <bean id="propertyConfig"

          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" lazy-init="false">

        <property name="locations">

            <list>

                <value>config.properties</value>

            </list>

        </property>

    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">

        <property name="driverClassName">

            <value>${driver}</value>

        </property>

        <property name="url">

            <value>${url}</value>

        </property>

        <property name="username">

            <value>${username}</value>

        </property>

        <property name="password">

            <value>${password}</value>

        </property>

    </bean>

    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">

        <property name="configLocation" value="classpath:sqlMapConfig.xml"/>

        <property name="dataSource" ref="dataSource"/>

    </bean>

    <bean id="transactionManager"

          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

        <property name="dataSource">

            <ref local="dataSource" />

        </property>

    </bean>

    <tx:annotation-driven transaction-manager="transactionManager" />

</beans>

 

web.xml配置:

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"

         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

         id="WebApp_ID" version="3.0">

    <display-name>weblog</display-name>

    <servlet>

        <servlet-name>mywebsocket</servlet-name>

        <servlet-class>com.chat.servlet.ChatWebSocketServlet</servlet-class>

    </servlet>

    <servlet-mapping>

        <servlet-name>mywebsocket</servlet-name>

        <url-pattern>*.do</url-pattern>

    </servlet-mapping>

    <servlet>

        <servlet-name>freemarker</servlet-name>

        <servlet-class>com.chat.servlet.FreeMarker</servlet-class>

    </servlet>

    <servlet-mapping>

        <servlet-name>freemarker</servlet-name>

        <url-pattern>/freemarker</url-pattern>

    </servlet-mapping>

    <welcome-file-list>

        <welcome-file>index.jsp</welcome-file>

    </welcome-file-list>

    <context-param>

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

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

    </context-param>

    <listener>

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

    </listener>

 

    <filter>

        <filter-name>CharacterEncodingFilter</filter-name>

        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

        <init-param>

            <param-name>encoding</param-name>

            <param-value>UTF-8</param-value>

        </init-param>

        <init-param>

            <param-name>forceEncoding</param-name>

            <param-value>true</param-value>

        </init-param>

    </filter>

    <filter-mapping>

        <filter-name>CharacterEncodingFilter</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>

 

    <filter>

        <filter-name>struts2</filter-name>

        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

    </filter>

 

    <filter-mapping>

        <filter-name>struts2</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>

 

</web-app>

报出如下异常:

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener

org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/../config.properties]

at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:87)

at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:686)

at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:661)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)

at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)

at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)

at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)

at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)

at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)

at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)

at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)

at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:650)

at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1582)

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)

at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)

at java.util.concurrent.FutureTask.run(FutureTask.java:138)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

at java.lang.Thread.run(Thread.java:619)

Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/../config.properties]

at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:140)

at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:181)

at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:161)

at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:78)

... 20 more

加载中
0
JustForFly
JustForFly

是不是应该这么写

<value>classpath:config.properties</value>


米扬
应该不是,我也这样写过,在tomcat启动的时候有问题。我用junit测试都好着。
返回顶部
顶部