[关闭]
@StarSky 2018-04-09T13:14:54.000000Z 字数 766 阅读 774

2018-04-09 Service 注入为 null

JAVA


多次在当前 class 中写 main 函数测试,结果 service 注入的总为空。
如果是测试需求需要在 test 中使用 ContextConfiguration 注解:

  1. @RunWith(SpringJUnit4ClassRunner.class)
  2. @ContextConfiguration(locations = {"classpath:spring-config-dao.xml"})
  3. @Resource
  4. private QueryRunner mysqlHelper;
  5. public class TestClient {
  6. @org.junit.Test
  7. public void testMYSQL(){
  8. try{
  9. Map<String, Object> resultMap = new HashedMap();
  10. 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','')";
  11. int lineCount = mysqlHelper.update(sql);
  12. System.out.print("== 成功插入 " + lineCount + " 条数据 ==" );
  13. }catch (Exception e){
  14. System.out.print(e);
  15. }
  16. }
  17. }

这样才能成功加载到对应的 bean。

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注