0

I'm trying to create a simple CRUD webapp. I use

  • Maven

  • Spring 4.3.2

  • Hibernate 5.2.2

  • MySQL

When I start my app I am getting

HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException

type Exception report

message Request processing failed; nested exception is java.lang.NullPointerException

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

java.lang.NullPointerException
    businessManager.service.BusinessServiceImpl.getAllBusiness(BusinessServiceImpl.java:48)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:498)
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    com.sun.proxy.$Proxy18.getAllBusiness(Unknown Source)
    businessManager.controller.BusinessController.getAllBusiness(BusinessController.java:31)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:498)
    org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)

    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Controller

@Controller
public class BusinessController {
    private BusinessService businessService;

    @Autowired(required = true)
    @Qualifier(value = "businessService")
    public void setBusinessService(BusinessService businessService) {
        this.businessService = businessService;
    }

    @RequestMapping(value = "business", method = RequestMethod.GET)
    public String getAllBusiness(Model model)
    {
        model.addAttribute("business", new Business());
        model.addAttribute("getAllBusiness", this.businessService.getAllBusiness());

        return "business";
    }
}

DaoImpl

@Repository
public class BusinessDaoImpl implements BusinessDao{
    private static Logger logger = LoggerFactory.getLogger(BusinessDaoImpl.class);
    private SessionFactory sessionFactory;
    @SuppressWarnings("unchecked")
    public List<Business> getAllBusiness() {
        Session session = this.sessionFactory.getCurrentSession();
        List<Business> businessList = session.createQuery("from Business").list();

        for (Business business : businessList)
        {
            logger.info("Business list: " + business);
        }
        return businessList;
    }
}

ServiceImpl

@Service("businessService")
public class BusinessServiceImpl implements BusinessService {
    private BusinessDao businessDao;

    public void setBusinessDao(BusinessDao businessDao) {
        this.businessDao = businessDao;
    }

    @Transactional
    public List<Business> getAllBusiness() {
        return businessDao.getAllBusiness();
    }
}

I'm grateful for any advice!

P.S. I'm just learning for Spring etc... Sorry, if it's nonsense

Vlad Yurevich
  • 305
  • 1
  • 3
  • 13
  • You should add code of `BusinessServiceImpl.java` – Jens Aug 16 '16 at 14:05
  • I don't think this is a dupe? He's asking about http 500, which is internal server error... Are you running your app in a container or as a stand-alone jvm? There may not be anything wrong with your application, but may be missing some configurations... Check logs, especially startup – niken Aug 16 '16 at 14:32

0 Answers0