解决方案 »

  1.   

    import org.junit.Assert;
    02
    import org.junit.BeforeClass;
    03
    import org.junit.Test;
    04
    import org.junit.runner.RunWith;
    05
    import org.springframework.beans.factory.annotation.Autowired;
    06
    import org.springframework.http.HttpMethod;
    07
    import org.springframework.mock.web.MockHttpServletRequest;
    08
    import org.springframework.mock.web.MockHttpServletResponse;
    09
    import org.springframework.test.context.ContextConfiguration;
    10
    import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    11
    import org.springframework.web.method.HandlerMethod;
    12
    import org.springframework.web.servlet.ModelAndView;
    13
    import    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
    14
     
    15
    @RunWith(SpringJUnit4ClassRunner.class)
    16
    @ContextConfiguration(locations = {"classpath:/WEB-INF/monitor-servlet.xml",   "classpath:/spring/spring-core.xml"})
    17
    public class JobControllerTest {
    18
        @Autowired
    19
        public RequestMappingHandlerAdapter handlerAdapter;
    20
        @Autowired
    21
        private JobController jobController;
    22
     
    23
        private static MockHttpServletRequest request;
    24
     
    25
        private static MockHttpServletResponse response;
    26
     
    27
        @BeforeClass
    28
        public static void before() {
    29
            request = new MockHttpServletRequest();
    30
            request.setCharacterEncoding("UTF-8");
    31
            response = new MockHttpServletResponse();
    32
        }
    33
     
    34
        @Test
    35
        public void testList() {
    36
            request.setRequestURI("/job/list");
    37
            request.setMethod(HttpMethod.POST.name());
    38
            ModelAndView mv = null;
    39
            try {
    40
                mv = handlerAdapter.handle(request, response, new     HandlerMethod(jobController, "list"));
    41
            } catch (Exception e) {
    42
                e.printStackTrace();
    43
            }
    44
     
    45
            Assert.assertNotNull(mv);
    46
            Assert.assertEquals(response.getStatus(), 200);
    47
            Assert.assertEquals(mv.getViewName(), "/job/job_list");
    48
        }
    49
    }
      

  2.   

    楼主参考一下http://www.cnblogs.com/alphablox/archive/2013/04/06/3002152.html
      

  3.   


    为什么这么说呢?
    spring有数据源死锁的问题。很多人遇到过,都给归于什么时间运行的比较常,或者并发比较大的原因,其实是spring事务管理的bug。要是你不用spring管理数据库事务的话,倒是可以用。