Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC error

    Hi All ,
    In my current project I am trying to use spring mvc using annotation. I have the following in my configuration xml sps-servlet.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schem...ontext-2.5.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-3.0.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schem...g-util-2.5.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <!-- Detect classes annotated with @Repository, @Component, @Service, @Controller, and register them as beans -->
    <context:component-scan base-package="com.abc.dao*,
    com.abc.businessObjects*.*, com.abc.validation,
    com.abc.search" />

    Now in there is a class called SearchAction which acts as the controller and it has the following

    @Controller
    public class SearchAction {

    private static final Logger logger = Logger.getLogger(SearchAction.class);

    public static final String URL_MAPPING = "/search";

    private Map<String, Object> session;

    private SessionContext sessionContext;

    @Autowired
    private SearchResultsChecksBO searchResultsChecksBO;


    @RequestMapping(value = URL_MAPPING, method = RequestMethod.GET)
    public ModelAndView setupForm(HttpSession session) {
    logger.error("Test");
    ModelAndView modelAndView = new ModelAndView(ViewConstants.SEARCH);
    populateSearchModel(modelAndView.getModelMap(), session);
    return modelAndView;
    }

    public Map<String, Object> getSession() {
    session = new HashMap<String, Object>();
    return session;
    }

    protected SessionContext getSessionContext() {
    // sessionContext = (SessionContext) getSession().get(ApplicationConstants.ABC_SESSION_ CONTEXT_KEY);
    if (sessionContext == null) {
    sessionContext = new SessionContext();
    getSession().put(ApplicationConstants.ABC_SESSION_ CONTEXT_KEY, sessionContext);
    }
    return sessionContext;
    }


    private void populateSearchModel(ModelMap model, HttpSession session) {
    //obviously a TODO
    String respStr = null;
    SessionContext sessionContext = this.getSessionContext();
    //UserContext userContext = sessionContext.getUserContext();
    UserContext userContext = new UserContext();
    userContext.setCompanyId("SPSTEST6");
    userContext.setCompanyName("");
    userContext.setUserId("TESTERJC");
    sessionContext.setUserContext(userContext);
    try {

    SearchResultsChecksDO displayObject = searchResultsChecksBO.getDataForPageLoad(userConte xt);
    respStr = displayObject.toJSON(userContext);
    }catch(Exception e){
    e.printStackTrace();
    }
    model.addAttribute("jsonValue",respStr);
    System.out.println("The jsonstring is ************************** "+respStr);

    }

    }


    Now the issue is that when i keep the class SearchResultsChecksBOImpl.java(implementation class) in one package as that of Search Action, it is working fine. But the moment I move this class to a different package of diff project and make my current project dependent on that. It breaks down and gives the following error while deploying

    DispatcherSer E org.springframework.web.servlet.FrameworkServlet initServletBean Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'searchAction' defined in file [C:\workspaces\sis_next_gen\spsWEB\WebContent\WEB-INF\classes\com\abc\search\SearchAction.class]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: com.abc.businessObjects.SearchResultsChecksBOImpl.

    The package com.abc.search and com.abc.businessObjects are two projects in the eclipse but i have shown the dependency between them.

    Now i am not able to understand why the spring is not able to pick this up. Is there any other configuration that needs to be taken care off. Also this work when i put them under same package.
Working...
X