小编fmu*_*car的帖子

如何解决Spring Controller测试用例中的NoSuchMethodError?

java.lang.NoSuchMethodError: 
org.junit.runner.notification.RunNotifier.testAborted(Lorg/junit/ 
runner/Description;Ljava/lang/Throwable;)
        at  org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestM­ethod(SpringJUnit4ClassRunner.java:
155) 
Run Code Online (Sandbox Code Playgroud)

并为控制器编写测试用例,为Spring Controller类新编写测试用例:

TestXController.java

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(locations={"file:D:/ABC/src/main/webapp/WEB-INF/
xyz-servlet.xml", 
"file:D:/ABC/src/main/webapp/WEB-INF/xyzrest-servlet.xml"}) 

    public class TestXController  { 

    @Inject 
    private ApplicationContext applicationContext; 

    private MockHttpServletRequest request; 
    private MockHttpServletResponse response; 
    private HandlerAdapter handlerAdapter; 
    private XController controller; 

    @Test 
    public void setUp() { 
       request = new MockHttpServletRequest(); 
       response = new MockHttpServletResponse(); 
       handlerAdapter =  applicationContext.getBean(HandlerAdapter.class); 
       // I could get the controller from the context here 
       controller = new XController(); 
    } 

    @Test 
    public void testgoLoginPage() throws Exception { 

        request.setAttribute("login", "0"); 

        final org.springframework.web.servlet.ModelAndView mav =  handlerAdapter.handle(request, response, controller); …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-test

6
推荐指数
1
解决办法
8147
查看次数

雄猫和防洪

我们正在使用Tomcat 7作为我们的Web应用程序.我们提供基于XML的API,以便我们的客户能够以机器对机器的方式与我们的服务器进行通信(无需Web浏览器).请求由servlet处理.

我们需要阻止用户连续发送过多请求.我们提供的一些服务涉及轮询结果,用户可以在没有任何暂停的情况下在循环中发出请求,每秒进行数十次请求.

我们如何保护自己免受无用的请求?当来自同一IP的请求太多时,是否有一种简单的方法可以在servlet入口级别阻止请求?是否有内置的Tomcat来处理这个问题?

java tomcat web-services servlets web-applications

6
推荐指数
1
解决办法
1053
查看次数

Java中的线程池

我使用ThreadPool在Java中编写应用程序.首先我创建新的ThreadPool:

private ExecutorService threadExecutor = Executors.newFixedThreadPool( 20 );
Run Code Online (Sandbox Code Playgroud)

然后我创建了一些Runnable对象.之后,我不时地执行我的ThreadPool传递相同的Runnable对象:

threadExecutor.execute(serverRunnable);
Run Code Online (Sandbox Code Playgroud)

我每20秒执行一次这个ThreadPool.我的问题是threadExecutor停止工作大约5分钟.它只是不执行Runnable对象.我注意到当我增加参数:

Executors.newFixedThreadPool( 20 );
Run Code Online (Sandbox Code Playgroud)

从20到100个ThreadPool将工作更长时间.任何人都可以解释为什么ThreadPool停止工作?

PS.我在Android中编写此代码

java multithreading android

5
推荐指数
1
解决办法
2293
查看次数