Spring注入Bean出现空指针异常
@Bean
    public ServletRegistrationBean ActionServlet() {
        ServletRegistrationBean registration = new ServletRegistrationBean();
        registration.setName("ActionServlet");
        registration.setOrder(1);
        registration.addUrlMappings("*.do");
        registration.setServlet(new ActionServlet());
        registration.addInitParameter("config", "/WEB-INF/conf/action_config.xml");
        registration.addInitParameter("ignoreCase", "N");
        registration.setLoadOnStartup(1);
        return registration;
    }
java.lang.NullPointerException: null
    at org.dom4j.io.SAXReader.read(SAXReader.java:284)
    at com.yuangou.ecp.bp.web.controller.ActionMappingsParse.parse(ActionMappingsParse.java:34)
    at com.yuangou.ecp.bp.web.controller.servlet.ActionServlet.init(ActionServlet.java:502)
    at javax.servlet.GenericServlet.init(GenericServlet.java:158)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1144)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:986)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4978)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedContext.deferredLoadOnStartup(TomcatEmbeddedContext.java:78)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.performDeferredLoadOnStartup(TomcatEmbeddedServletContainer.java:288)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:211)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:297)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:145)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134)
    at com.murong.ecp.bp.common.util.ECPApplication.run(ECPApplication.java:30)
    at com.murong.ecp.netpay.jnefss.web.SpringBootApplication.main(SpringBootApplication.java:18)

2个回答

看一下SpringBootApplication启动类的第18行啊

qq_43631197
你是我一生的风景 启动类没有问题
5 个月之前 回复

1.首先你要确保,你写bean的这个类被扫描到了。
2.其次你要确保,你使用这个bean的类被扫描到了
3. 你给的这些代码都没有用,我们都不知到你怎么使用的。如果只是看这个bean,是没有问题的。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐