次の例外が発生しています。その行が原因です
セッション ss=session.getCurrentSession(); java.lang.NullPointerException com.mkyong.common.dao.UserDao.saveUser (UserDao.java:25) で com.mkyong.common.controller.JSONController.getShopInJSON (JSONController.java:31) で sun.reflect.NativeMethodAccessorImpl.invoke0(ネイティブメソッド) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) で sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) で java.lang.reflect.Method.invoke(Method.java:601) で org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176) で org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426) で org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414) で org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790) で org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719) で org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) で org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560) で javax.servlet.http.HttpServlet.service(HttpServlet.java:647) で javax.servlet.http.HttpServlet.service(HttpServlet.java:728) で org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:305) で org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) で org.apache.catalina.core.StandardWrapperValve.invoke (StandardWrapperValve.java:222) で org.apache.catalina.core.StandardContextValve.invoke (StandardContextValve.java:123) で org.apache.catalina.authenticator.AuthenticatorBase.invoke (AuthenticatorBase.java:472) で org.apache.catalina.core.StandardHostValve.invoke (StandardHostValve.java:171) で org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) で org.apache.catalina.valves.AccessLogValve.invoke (AccessLogValve.java:936) で org.apache.catalina.core.StandardEngineValve.invoke (StandardEngineValve.java:118) で org.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.java:407) で org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004) で org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) で org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) で java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1145) で java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) で java.lang.Thread.run(Thread.java:722) で
私のdaoクラスは次のとおりです。
package com.mkyong.common.dao;
import org.hibernate.SessionFactory;
import org.hibernate.Session;
import com.mkyong.common.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
public class UserDao {
private SessionFactory session;
public void setSessionFactory(SessionFactory session){
if(session == null){
throw new IllegalStateException();
}
this.session=session;
}
public int saveUser(User user) {
Session ss=session.getCurrentSession();
System.out.println(user.getUserName());
System.out.println(user.getPassword());
//Session ss=session.getCurrentSession();
ss.save(user);
return 1;
}
}
私の設定ファイルは次のとおりです。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:property-placeholder location="classpath:jdbc.properties" />
<context:component-scan base-package="com.mkyong.common.controller" />
<context:annotation-config/>
<mvc:annotation-driven />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${database.driver}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.user}" />
<property name="password" value="${database.password}" />
</bean>
<bean id="SessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.mkyong.common.model.User</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
</props>
</property>
</bean>
<bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="SessionFactory" ref="SessionFactory" />
</bean>
</beans>