51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 4382|回复: 0
打印 上一主题 下一主题

[原创] Junit 读取Spring配置文件出错

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2010-2-2 20:40:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
<?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:aop="http://www.springframework.org/schema/aop"
        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.0.xsd
                        http://www.springframework.org/schema/aop
                        http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
                        http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
        <tx:advice id="txAdivce" transaction-manager="transactionManager">
                <tx:attributes>
                        <tx:method name="get*" read-only="true" />
                        <tx:method name="find*" read-only="true" />
                        <tx:method name="add*" propagation="REQUIRED" />
                        <tx:method name="delete*" propagation="REQUIRED" />
                        <tx:method name="modify*" propagation="REQUIRED" />
                        <tx:method name="update*" propagation="REQUIRED" />
                </tx:attributes>
        </tx:advice>

        <aop:config proxy-target-class="true">
                <aop:pointcut id="servicePointcut" expression="execution(* com.zju.cdpf.biz.service.*.*(..))"/>
            <aop:advisor pointcut-ref="servicePointcut" advice-ref="txAdivce" />
        </aop:config>

        <import resource="module/web-action.xml" />
        <import resource="module/biz-dao.xml"/>
        <import resource="module/biz-service.xml"/>
        <import resource="module/datasource/datasource.xml"/>

        <!-- 使用config配置文件 -->
        <bean id="propertyConfigurer"  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                <property name="locations">
                        <list>
                                <value>/WEB-INF/config/config.properties</value>
                        </list>
                </property>
        </bean>
</beans>

Junit 读取Spring配置文件出错,主要问题是不能读取Properties文件

Exception in thread "main" org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [WEB-INF/config/config.properties] cannot be opened because it does not exist
Caused by: java.io.FileNotFoundException: class path resource [WEB-INF/config/config.properties] cannot be opened because it does not exist
        at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:135)
        at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:179)
        at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:158)
        at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:69)
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:414)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:328)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
        at Test.main(Test.java:10)
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-11-19 04:33 , Processed in 0.068545 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表