Crowdfunding:Test data source for database connection
程序员文章站
2022-05-26 17:54:15
...
1、首先在webui模块创建日志配置文件:log4j.properties
# DEBUG < INFO < WARN < ERROR < FATAL
log4j.rootLogger=DEBUG,myConsole
log4j.appender.myConsole=org.apache.log4j.ConsoleAppender
log4j.appender.myConsole.Target=System.out
log4j.appender.myConsole.layout=org.apache.log4j.PatternLayout
log4j.appender.myConsole.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n
#log4j.logger.org.hibernate=INFO
2、接着需要在此模块导入spring-test、junit依赖,然后创建测试类进行测试并进行日志打印:
package com.jcn.crowdfunding.test;
import java.sql.Connection;
import javax.sql.DataSource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
(
locations= {
"classpath:spring-persist-mybatis.xml"
}
)
public class CrowdfundingTest {
//装配数据源
@Autowired
private DataSource dataSource;
@Test
public void testConnection() throws Exception {
Connection connection = dataSource.getConnection();
System.out.println(connection);
}
}
打印结果:
下一篇: js编辑器插件