Java Spring Web App - 数据库访问异常

时间:2011-01-10 21:24:40

标签: java spring tomcat jersey

嗨iv一直在努力解决这个错误并且真的无法弄清楚它为什么会发生,我有一个使用spring simpleJdbctemplate访问数据库的web应用程序我可以在本地使用它并且它已经过测试但是当我部署时应用程序运动衫在服务器上运行查询时遇到一些问题,这是来自tomcat日志的堆栈跟踪

10-Jan-2011 21:15:28 com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException
SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
java.lang.NullPointerException
    at example.jersey.spring.dao.testDAO.getUsers(testDAO.java:20)
    at example.jersey.spring.MyResource.getIt(MyResource.java:23)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:168)
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:70)
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:279)
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:86)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:74)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1357)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1289)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1239)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1229)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:497)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:684)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)

这是我的资源

 @GET 
    @Produces("text/plain")
    public String getIt() {
        return "the number of users are " +db.getUsers();
    }

TestDAO.java

 SimpleJdbcTemplate simpleJdbcTemplate ;

        public void setDataSource(final DataSource dataSource) {
            this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
        }

的applicationContext.xml

  <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${username}"/>
        <property name="password" value="${password}"/>
    </bean>

<bean id="testDAO" class="com.example.testDAOimpl">
        <property name="dataSource" ref="dataSource"/>
    </bean>

在eclipse中本地运行db.getusers返回 - 正确值为1所以我无法理解为什么它在部署时不起作用

任何帮助非常感谢

(似乎与本地设置和服务器设置没有什么区别)如果有人遇到过这个帮助,我们非常感激)

由于 克里斯

2 个答案:

答案 0 :(得分:1)

不确定这是不是你的问题。但我面临着类似的问题。最终发生的事情是我在服务器代码中的类路径上缺少MimeMultipart.class。 Jersey无法找到该类,因此无法正确映射服务器请求。最奇怪的是我从未在服务器端看到任何类型的错误消息,表明找不到类。

答案 1 :(得分:0)

假设您使用bean工厂,请执行以下操作以从spring开始:

BeanFactoryLocator beanFactoryLocator = SingletonBeanFactoryLocator.getInstance();
BeanFactoryReference beanFactoryReference = beanFactoryLocator.useBeanFactory("ctx");

testDAOimpl myDao = (testDAOimpl)beanFactoryReference.getFactory().getBean("testDAO");