스프링 오류

예외 메시지 내용

javax.servlet.ServletException: 서블릿 [appServlet]을(를) 위한 Servlet.init() 호출이 예외를 발생시켰습니다.


예외 메시지 상세 내용 중 일부

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'boardController': Unsatisfied dependency expressed through field 'boardService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'kr.green.spring.service.BoardService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}


원인

 - ServiceImp 클래스에 @Service 어노테이션을 추가하지 않음


해결

- ServiceImp 클래스에 @Service 어노테이션을 추가

1
2
3
@Service
public class BoardServiceImp implements BoardService {
}

cs


스프링 오류

경고 메시지 내용(sts 콘솔창)

WARN : org.springframework.web.servlet.PageNotFound - No mapping for GET /spring/board/list


원인

 1. 해당 URI를 처리하는 메소드를 생성 안한 경우

 2. 해당 URI를 처리하는 메소드를 만들었지만 해당 클래스에 @Controller 어노테이션을 안 쓴경우


해결

 1. 컨트롤러에 해당 URI를 처리하는 메소드를 생성

1
2
3
4
5
6
7
8
9
@Controller
public class BoardController {
    @RequestMapping(value = "/board/list", method = RequestMethod.GET)
    public ModelAndView boardListGet(ModelAndView mv) {
        mv.setViewName("/board/list");
        //기능 코드는 생략
        return mv;
    }
}

cs


2. 컨트롤러에 @Controller 어노테이션을 추가

1
2
3
4
@Controller
public class BoardController {
    //... 컨트롤러 안 메소드 생략
}
cs


스프링 오류

오류 메시지 상세 내용 중 일부(예시)

ERROR: org.springframework.web.context.ContextLoader - Context initialization failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in ServletContext resource [/WEB-INF/spring/root-context.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [C:\Users\Administrator\Documents\workspace-spring-tool-suite-4-4.7.0.RELEASE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\spring\WEB-INF\classes\mappers\BoardMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'kr.green.spring.vo.BoardVo'.  Cause: java.lang.ClassNotFoundException: Cannot find class: kr.green.spring.vo.BoardVo


원인

 - BoardMapper(XML파일)에서 select로 작업할 때 발생할 수 있는 에러

 - resultType으로 BoardVo를 설정했는데 BoardVo를 찾지 못해서 발생

 

해결

- servlet-context.xml파일에서 component-scan의 base-package를 모든 패키지가 포함되도록 수정해야함

1
2
3
4
5
<!-- 수정전 -->
<context:component-scan base-package="kr.green.spring.controller" />
 
<!-- 수정후 : BoardVo가 kr.green.spring.vo 패키지에 있는 경우 -->
<context:component-scan base-package="kr.green.spring.*" />
cs


스프링 오류

예외 메시지 내용

Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'A' not found. Available parameters are [B]


예외 메시지 상세 내용 중 일부

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'A' not found. Available parameters are [B]


원인

 - Dao에서 넘겨준 매개변수 객체 B에 멤버 변수 A가 없는 경우


해결

 - 객체 B의 멤버 변수 A가 있는지 확인하여 없으면 추가

 - 있는 경우에 에러가 나는 경우

  1. Dao에 @Param("B")을 넣어줬으면 Mapper에서 #{B.A}로 사용

  2. Dao에 @Param("B")를 안 넣어줬으면 Mapper에서 #{A}로 사용


+ Recent posts