@StarSky
2018-04-09T13:14:54.000000Z
字数 766
阅读 774
JAVA
多次在当前 class 中写 main 函数测试,结果 service 注入的总为空。
如果是测试需求需要在 test 中使用 ContextConfiguration 注解:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring-config-dao.xml"})
@Resource
private QueryRunner mysqlHelper;
public class TestClient {
@org.junit.Test
public void testMYSQL(){
try{
Map<String, Object> resultMap = new HashedMap();
String sql = "INSERT INTO tts_info (ip,system_id,request_id,type,text,session_id,time_stamp,time_consume,voice_file_path,error_code) VALUES('66.66.66.66','system_id','request_id','1','测试文本','session_id','2018-03-31 23:30:04','55','/export/home/aiusr/saber/voice/111.wav','')";
int lineCount = mysqlHelper.update(sql);
System.out.print("== 成功插入 " + lineCount + " 条数据 ==" );
}catch (Exception e){
System.out.print(e);
}
}
}
这样才能成功加载到对应的 bean。