关于ssm框架的一系列的问题

作为一名小白  通过自己研究ssm框架 发现好多新的知识

1.在传统的web模式下  一般配置文件都是放在web-inf下的比如  spring的  logging的等等配置文件;
这种情况下  把项目发布到tomcat上的时候  tomcat将配置文件是放在web-inf下面的
与此配套的一些路径是这么配置的

web.xml中配置一些加载文件是这么配置的

<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mybatis.xml</param-value>
</context-param>

spring中加载配置文件的时候是这么配置
 <bean id="propertyConfigurer"  
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
        <property name="location" value="file:WebContent/WEB-INF/jdbc.properties" />  
    </bean>  
这种情况下用junit单元测试的时候需要写个类JUnit4ClassRunner继承SpringJUnit4ClassRunner 来动态的配置log4j.properties文件否则运行测试类的时候一直报


log4j:WARN No appenders could be found for logger(org.springframework.test.context.junit4.SpringJUnit4ClassRunner).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

测试类代码注解如下
@RunWith(JUnit4ClassRunner.class) //表示继承了SpringJUnit4ClassRunner类
@ContextConfiguration(locations={"file:WebContent/WEB-INF/spring-mybatis.xml"})
项目目录结构如下

但是如果将配置文件放到新建的资源文件夹resource中  则发布项目的时候 配置文件会自动加载到class目录下 这是时候配置的路径就改成下面的情况
web.xml配置文件用
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mybatis.xml</param-value>
</context-param>
spring配置如下
 <property name="location" value="classpath:jdbc.properties" />  

junit测试类注释配置如下

@RunWith(SpringJUnit4ClassRunner.class) //表示继承了SpringJUnit4ClassRunner类
@ContextConfiguration(locations={"classpath:spring-mybatis.xml"})
此时的项目路径如下




学到的其他东西
1.classpath的路径指的是classes目录下
2.当运行junit测试类一直不打日志则说明日志文件路径不对 可以对SpringJUnit4ClassRunner进行重写动态加载日志文件路径
3.spring最好用高版本的一个版本不要多个版本互用





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值