Spring中的经典疑问: Error creating bean with name 'urlMapping' ...

正在学习spring的多动作控制器,然而配置完成运行后,出现了这样的错误信息,我估计很多老鸟见过,如下:

 

Error creating bean with name 'urlMapping' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multiController' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.page.NewIndexShowListController]: Constructor threw exception; nested exception is java.lang.NullPointerException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:443)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:459)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:340)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:307)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4042)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4348)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

  我查过好多网上信息,都没有解决,再看我的applicationContent.xml配置

 

 <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
   <property name="mappings">
    <props>
     
     <prop key="/*Page.htm">multiController</prop>
     
     </props>
   </property>
  </bean>


     <bean id="propMethodResolver" 
            class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
        <property name="mappings">
            <props>
                <prop key="/nextPage.htm">nextPage</prop>
                <prop key="/previousPage.htm">previousPage</prop>
                <prop key="/firstPage.htm">firstPage</prop>
                <prop key="/lastPage.htm">lastPage</prop>
                <prop key="/getPage.htm">getPage</prop>
            </props>
        </property>
    </bean> 
    
    <bean id="multiController" class="com.page.NewIndexShowListController">
        <property name="methodNameResolver">
            <ref bean="propMethodResolver"/>
        </property>
        <property name="myuserDAO">
            <ref bean="MyuserDAO"/>
        </property>
    </bean>

 以及 web.xml配置

 

   <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.do,*.htm</url-pattern>
    </servlet-mapping>
    
    <filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
   

    <init-param>
       <param-name>encoding</param-name>
       <param-value>GBK</param-value>
    </init-param>

    <init-param>
       <param-name>forceEncoding</param-name>
       <param-value>true</param-value>
    </init-param>

</filter>

 

<filter-mapping>
  <filter-name>encodingFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  前台的简单代码:

 

 
  <body>
    
   <a href="nextPage.htm">下一页</a>
    <a href="previousPage.htm">前一页</a>
    <a href="firstPage.htm">首页</a>
    <a href="lastPage.htm">尾页</a>
    <a href="getPage.htm">某页</a>
  
  
  </body>

  后台的代码:

 

public class NewIndexShowListController extends MultiActionController{
    private MyuserDAO myuserDAO;
    Map map=new HashMap();
    @SuppressWarnings("unchecked")
    List<Myuser> userList=myuserDAO.findAllOrderByTime();
    PageModel pageModel=new PageModel(userList, 5);
    int pageCount=pageModel.getTotalPages();
    
    public ModelAndView nextPage(HttpServletRequest req,HttpServletResponse res)throws Exception
    {
        
        System.out.println("将显示下一页");
        List sublist=pageModel.getNextPage();
         for(int i = 0; i < sublist.size(); i++) 
            {  
                System.out.println(sublist.get(i));  
                
               
            }  
        map.put("sublist",sublist);
        return new ModelAndView("success","map",map);
        
    }
    public ModelAndView previousPage(HttpServletRequest req,HttpServletResponse res)throws Exception
    {
        
        System.out.println("将显示前一页");
        List sublist=pageModel.getPreviousPage();
        for(int i = 0; i < sublist.size(); i++) 
        {  
            System.out.println(sublist.get(i));  
           
        } 
        map.put("sublist",sublist);
        return new ModelAndView("success","map",map);
    }
    public ModelAndView firstPage(HttpServletRequest req,HttpServletResponse res)throws Exception
    {   
        System.out.println("将显示首页");
        
        
        List sublist=pageModel.getFirstPage();
        for(int i=0;i<sublist.size();i++)
        {
            System.out.println(sublist.get(i));
        }
        map.put("sublist",sublist);
        return new ModelAndView("success","map",map);
    }
    public ModelAndView lastPage(HttpServletRequest req,HttpServletResponse res)throws Exception
    {
        System.out.println("将显示尾页");
        
        List sublist=pageModel.getLastPage();
        for(int i=0;i<sublist.size();i++)
        {
            System.out.print(sublist.get(i));
        }
        map.put("sublist",sublist);
        return new ModelAndView("success","map",map);
    }
    
    public ModelAndView getPage(HttpServletRequest req,HttpServletResponse res)throws Exception
    {
        
        int pagenum=Integer.parseInt(req.getParameter("pagenum"));
        List sublist=pageModel.getObjects(pagenum);
         for(int i = 0; i < sublist.size(); i++) 
            {  
                System.out.println(sublist.get(i));  
               
            }  
         map.put("sublist",sublist);
         return new ModelAndView("success","map",map);
    }
    
    
     public void setMyuserDAO(MyuserDAO myuserDAO)
        {
            this.myuserDAO=myuserDAO;
        }
     public MyuserDAO getMyuserDAO()
        {
            return this.myuserDAO;
        }
}

  控制器代码继承了MuitiActionCotroller,不明白报这样的错误说明了什么,哪里出了错误?虚心求教,感激不尽~

查看全部
coolgaojian
coolgaojian
2012/04/07 10:30
  • spring
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

0个回复