2014-12-05 185 views
0

當我把下面的依賴關係(和它的所有傳遞DEPS的爲好)對我的類路徑:碼頭ServletTester拋出拋出:SecurityException

<dependency> 
    <groupId>org.eclipse.jetty</groupId> 
    <artifactId>test-jetty-servlet</artifactId> 
    <version>8.1.14.v20131031</version> 
</dependency> 

並運行此JUnit測試:

public class MySimpleTest { 
    private ServletTester tester; 

    @Before 
    public void setUp() { 
     tester = new ServletTester(); 
     tester.contextPath = "http://localhost:8080/myapp/location"; 
     tester.addServlet(MyAppMockEndpoint.class, "/address/*"); 
     tester.start(); 
    } 

    @After 
    public void tearDown() { 
     tester.stop(); 
    } 

    @Test 
    public void test() { 
     // Dummy assertion that is always true, just to prove its not 
     // my code throwing the exception. 
     Assert.assertTrue(System.currentTimeMillis() > 0L); 
    } 

    public class MyAppMockEndpoint extends HttpServlet { 
     @Override 
     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
      response.getWriter().println(provideJson()) 
      response.getWriter().flush() 
     } 

     public String provideJson() { 
      return "{ \"id\": 5, \"fizz\": \"true\", \"buzz\": \"false\" }"; 
     } 
    } 
} 

我得到這個:

java.lang.SecurityException: class "javax.servlet.DispatcherType"'s signer information does not match signer information of other classes in the same package 
    at java.lang.ClassLoader.checkCerts(ClassLoader.java:952) 
    at java.lang.ClassLoader.preDefineClass(ClassLoader.java:666) 
    at java.lang.ClassLoader.defineClass(ClassLoader.java:794) 
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) 
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) 
    <giant stack trace omitted for brevity> 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) 

爲什麼?什麼是修復?如果其中一個傳遞依賴關係被簽名,我該如何判斷哪一個依賴關係?有沒有一種方法可以指定所有傳遞代碼的無符號版本?這裏還有其他問題,還是更好的解決方案?

+0

將'mvn dependency:tree'的輸出添加到問題中。您的依賴關係可能存在衝突。 – 2014-12-08 15:10:46

回答

0

這是值得的。我有一個類似的問題,並通過刪除冗餘的servlet-api(我在我的路徑中提供)(javax.servlet servlet-api 2.3提供)來擺脫它。

我能夠從命令行運行測試(在我的情況下sbt),但是當我從Intellij運行它們時,它們墜毀。

相關問題