使用名称创建bean时出错(自动装配问题)

时间:2018-04-13 16:36:39

标签: java spring hibernate maven classpath

我是Spring / Hibernate / Maven的新手,我得到以下error。我正在使用jdk 1.8和Eclipse。

我的项目分为两个Maven项目。

  1. 前端 - 由jsp,控制器等组成
  2. 后端 - 由与hibernete相关的东西dao,服务等组成。
  3. 我的控制器类

    import javax.servlet.http.HttpServletResponse;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.security.core.Authentication;
    import org.springframework.security.core.context.SecurityContextHolder;
    import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.servlet.ModelAndView;
    
    import com.xyz.retrospective.backend.dao.CommentDAO;
    
    
    
    @Controller
    public class PageController {
    
    @Autowired
    private CommentDAO commentDAO ;
    
    @RequestMapping(value = {"/", "/home", "/index"})
    public ModelAndView index() {       
        ModelAndView mv = new ModelAndView("home");     
        return mv;  
    }
    @RequestMapping(value = "/${userId}/CurrentIteration")
    public ModelAndView showCategoryProducts(@PathVariable("userId") int userId) 
    {       
        ModelAndView mv = new ModelAndView("currentiteration");
    
        mv.addObject("commentTypeList",commentDAO.listCommentTypes());
        return mv;              
    }   
     }
    

    我的道教课程

    package com.xyz.retrospective.backend.dao;
    
    import java.util.List;
    
    import org.springframework.stereotype.Repository;
    
    import com.xyz.retrospective.backend.dto.CommentType;
    
    
    public interface CommentDAO {
    
      List<CommentType> listCommentTypes();
    }
    

    我的daoimpl课程

    package com.xyz.retrospective.backend.daoimpl;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import org.springframework.stereotype.Repository;
    
    import com.xyz.retrospective.backend.dao.CommentDAO;
    import com.xyz.retrospective.backend.dto.CommentType;
    
     @Repository("commentDAO")
     public class CommentDAOImpl implements CommentDAO{
    
    private static List<CommentType> commentTypes = new ArrayList<>();
    static {
        CommentType ct1 = new CommentType();
        ct1.setCommentTypeId("1");
        ct1.setCommentTypeDescription("WhatWentWell");
    
        CommentType ct2 = new CommentType();
        ct2.setCommentTypeId("2");
        ct2.setCommentTypeDescription("WhatDidNot");
    
        CommentType ct3 = new CommentType();
        ct3.setCommentTypeId("3");
        ct3.setCommentTypeDescription("WhatCouldHaveBeenBetter");
    
        commentTypes.add(ct1);
        commentTypes.add(ct2);
        commentTypes.add(ct3);
    }
    
    @Override
    public List<CommentType> listCommentTypes() {
        // TODO Auto-generated method stub
        return commentTypes;
    }
    
    }
    

    分配器一servlet.xml中

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd    
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd       
    ">
    
    
    
    
    <context:component-scan base-package="com.*"/>
    
    
        <!-- Loading static resources -->
    <mvc:annotation-driven />
    
    <mvc:resources location="/assets/" mapping="/resources/**" />
    
    
    
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    
    </bean>
    
    <bean id="multipartResolver"
        class="org.springframework.web.multipart.support.StandardServletMultipartResolver"/>
    
    
    
    
    
    <bean id="viewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
         <property name="viewResolvers" ref="viewResolver" />
    </bean> 
    
    </beans>
    

    可能是什么问题?

1 个答案:

答案 0 :(得分:0)

前端的maven构建作业不是打包后端类并包含它们。您需要创建另一个目标来编译所需的类并创建一个可以包含在前端构建中的jar。或者只做一个项目。