Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named '~~Service' is defined

boingboing·2023년 8월 30일
0

현상

컨트롤러에서 Service를 호출했는데 발생

원인

Spring이 해당 빈을 찾을 수 없음

해결

1.

@Service("myService")
public interface myService {

어노테이션을 통해 서비스로 등록해 줌.

2. Service에 잘못 붙인 annotation 제거

실제 구현체인 Impl파일을 Service로 만들어야 함.
abstract파일인 Service에 안 붙이고, impl에 붙임.

3. Override 시킴

ServiceImpl의 함수에 Service의 함수를 구체화 할 경우 @Override 어노테이션 붙여 줌.

public interface ProbioService {
	/* Service는 인터페이스로 정의함. 서비스는 Implement를 가리키지만 Interface로, 내용 코딩 불가
	 * Method 선언만 가능하고, 구현은 Implement에서 함. 
	 */
	int selectPoipIndividual() throws Exception;
}
@Service("probioService")
public class ProbioServiceImpl implements ProbioService {
	
	@Resource(name="probioMapper")
	private ProbioMapper probioMapper;
	
    
	@Override
	public int selectPoipIndividual() throws Exception{
		
		return 3;
	}
}

0개의 댓글