Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java servlet上的jhipster注入_Java_Servlets_Jhipster - Fatal编程技术网

Java servlet上的jhipster注入

Java servlet上的jhipster注入,java,servlets,jhipster,Java,Servlets,Jhipster,我创建了一个servlet,但我无法注入存储库对象。有人有这个问题吗 WebConfigure中的我的配置: @Override public void onStartup(ServletContext servletContext) throws ServletException { log.info("Web application configuration, using profiles: {}", Arrays.toString(env.getActiveProfiles())

我创建了一个servlet,但我无法注入存储库对象。有人有这个问题吗

WebConfigure中的我的配置:

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    log.info("Web application configuration, using profiles: {}", Arrays.toString(env.getActiveProfiles()));
    // Create the dispatcher servlet's Spring application context
    AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext();
    dispatcherServlet.register(WebMvcAutoConfiguration.class);

    // Register and map the dispatcher servlet
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServlet));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
我的servlet:

 @WebServlet(urlPatterns = "/servlet/preview")
    public class ServletPreViewHtml extends HttpServlet {
        private static final long serialVersionUID = 1L;

        @Autowired
        private PagecontentRepository pagecontentRepository;

        public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException{
            doGet(request,response);
        }
        public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException{
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            Pagecontent p = pagecontentRepository.getOne(2l); //line 34
            out.println(p.getFullHtml());
始终向我返回以下错误:

java.lang.NullPointerException:在 br.com.dmsolutions.netfarmacontentmanager.web.rest.ServletPreViewHtml.doGet(ServletPreViewHtml.java:34)


NPE的行:
pagecontentRepository.getOne(2L)

我宁愿使用
@WebServlet
,这样Spring就可以注入你的存储库。

我宁愿使用
@Controller
,这样Spring就可以注入你的存储库。

我同意Gaël Marziou,但您也可以使用Spring Boot 1.3的一部分
@ServletComponentScan


我同意Gaël Marziou的观点,但您也可以使用Spring Boot 1.3的一部分
@ServletComponentScan