4

我的安装(JDK 1.7)遇到了阻塞问题。基本上我有以下NPE:

10:19:17.548 [main] ERROR o.s.t.w.s.TestDispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter]: Constructor threw exception; nested exception is java.lang.NullPointerException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1007) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:953) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:289) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.createDefaultStrategy(DispatcherServlet.java:810) ~[spring-webmvc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.getDefaultStrategies(DispatcherServlet.java:779) ~[spring-webmvc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.initHandlerAdapters(DispatcherServlet.java:587) ~[spring-webmvc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.initStrategies(DispatcherServlet.java:444) ~[spring-webmvc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.onRefresh(DispatcherServlet.java:432) ~[spring-webmvc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:525) ~[spring-webmvc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459) ~[spring-webmvc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) [spring-webmvc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at javax.servlet.GenericServlet.init(GenericServlet.java:160) [tomcat-servlet-api-7.0.37.jar:3.0.FR]
    at org.springframework.test.web.servlet.MockMvcBuilderSupport.createMockMvc(MockMvcBuilderSupport.java:53) [spring-test-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder.build(DefaultMockMvcBuilder.java:207) [spring-test-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at com.mycompany.ui.controller.ConnectionInfosControllerTest.setup(ConnectionInfosControllerTest.java:41) [test-classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_21]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_21]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_21]
    at java.lang.reflect.Method.invoke(Method.java:601) ~[na:1.7.0_21]
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) [junit-4.11.jar:na]
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.11.jar:na]
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) [junit-4.11.jar:na]
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) [junit-4.11.jar:na]
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) [spring-test-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83) [spring-test-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) [spring-test-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) [spring-test-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88) [spring-test-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) [junit-4.11.jar:na]
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) [junit-4.11.jar:na]
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) [junit-4.11.jar:na]
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) [junit-4.11.jar:na]
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) [junit-4.11.jar:na]
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) [spring-test-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) [spring-test-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309) [junit-4.11.jar:na]
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) [spring-test-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) [.cp/:na]
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) [.cp/:na]
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) [.cp/:na]
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) [.cp/:na]
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) [.cp/:na]
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) [.cp/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter]: Constructor threw exception; nested exception is java.lang.NullPointerException
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1000) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    ... 44 common frames omitted
Caused by: java.lang.NullPointerException: null
    at java.nio.charset.Charset.put(Charset.java:550) ~[na:1.7.0_21]
    at java.nio.charset.Charset.access$300(Charset.java:276) ~[na:1.7.0_21]
    at java.nio.charset.Charset$4.run(Charset.java:593) ~[na:1.7.0_21]
    at java.nio.charset.Charset$4.run(Charset.java:585) ~[na:1.7.0_21]
    at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0_21]
    at java.nio.charset.Charset.availableCharsets(Charset.java:584) ~[na:1.7.0_21]
    at org.springframework.http.converter.StringHttpMessageConverter.<init>(StringHttpMessageConverter.java:66) ~[spring-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.http.converter.StringHttpMessageConverter.<init>(StringHttpMessageConverter.java:56) ~[spring-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.<init>(AnnotationMethodHandlerAdapter.java:201) ~[spring-webmvc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.7.0_21]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[na:1.7.0_21]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_21]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525) ~[na:1.7.0_21]
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    ... 46 common frames omitted

我强烈怀疑它与以下错误有关:请参阅此处的报告

我正在拼命寻找解决方法。注意,我没有接触过jdk的安装。我没有添加或删除任何字符集...

任何人都可以帮忙吗?

编辑 1 :在此处查看其他错误报告并注意“出于某种原因”...

编辑2 :我有关于上述问题的更多信息:我在一个单独的项目中添加了以下测试用例:

package pack;

import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.Set;

public class TestCase {
    public static void main(String[] args) {
        Set set = Charset.availableCharsets().keySet();
        for (Iterator iterator = set.iterator(); iterator.hasNext();) {
            String s = (String) iterator.next();
            System.out.println(s);
        }
    }
}

我注意到测试用例运行没有任何错误

现在,当我将相同的测试用例添加到我们的项目(使用 maven 构建)时,我遇到了相同的 NPE:

Exception in thread "main" java.lang.NullPointerException
    at java.nio.charset.Charset.put(Charset.java:550)
    at java.nio.charset.Charset.access$300(Charset.java:276)
    at java.nio.charset.Charset$4.run(Charset.java:593)
    at java.nio.charset.Charset$4.run(Charset.java:585)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.nio.charset.Charset.availableCharsets(Charset.java:584)
    at pack.TestCase.main(TestCase.java:9)

因此,我怀疑它可能与我们的 maven 配置有关。任何人都知道在多模块 Maven 配置中可能导致此字符集问题的原因是什么?

编辑 3:有效的 POM 太长。这是它的pastebin:这里的pastebin

编辑 4:我设法查明了有问题的依赖关系。这里是:

<dependency>
    <groupId>com.sybase</groupId>
    <artifactId>jconn4</artifactId>
    <version>7.07.GA</version>
    <scope>runtime</scope>
</dependency>

通过删除这种依赖关系,TestCase 可以正确执行并打印出所有可用的字符集。但是,我们的应用程序确实需要一个数据库驱动程序。任何人都知道 sybase jdbc 驱动程序出了什么问题?

4

2 回答 2

2

事实证明这是Sybase JDBC 驱动程序中的一个错误,正如您在此处看到的那样。从上面的链接中引用 Sybase JDBC 驱动程序的不满用户:

不过,没有什么应该让我感到惊讶,因为当前的 Sybase 驱动程序已完全损坏,并且已经使用了一年多!它包含一个 CharsetProvider,它返回一个空迭代器,导致 Charset.availableCharsets() 抛出一个空指针异常。Spring等很多框架调用Charset.availableCharsets()。

我不确定如何向 Sybase/SAP 报告这个错误......

于 2013-06-10T12:21:23.030 回答
0

不确定是否有人仍在寻找答案......但是,是的,这是 Sybase 驱动程序 jar 中的一个错误。在 SAP 中用 jconn4.jar 讨论 NPE这个链接中有讨论和解决方案。我刚刚遇到了同样的问题,并通过更换一个较新的罐子得到了解决(结果我们使用的是非常旧的罐子。)

于 2016-12-20T04:14:25.037 回答