스프링 오류

예외 메시지 내용

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


스프링 오류

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

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}로 사용


스프링 오류

 예외 메시지 내용

Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException


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

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException

### Error querying database.  Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ~~


원인1

 - 잘못된 SQL 문법을 사용

해결1

 - 올바른 SQL문으로 수정


원인2

 - Mapper에서 외부 정보를 ${변수명}으로 표현한 경우

해결2

 - 외부 정보를 #{변수명}으로 수정



+ Recent posts