您的位置:首页 > 其它

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

2017-05-10 10:48 399 查看
作为一名小白  通过自己研究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最好用高版本的一个版本不要多个版本互用

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: