[Spring] Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
프로젝트를 합치는데 많이 나오는 에러이다. @Controller, @Service, @Repository 등을 제시하지 않은 annotions 의 문제일 수 도 있지만... 대부분 오류는 제대로 결합되지 않은 문제였다.
특히 java 파일에서 controller, service, dao, sqlsession 에서 모두 문제가 발생했다면 제대로 연결하지 않은 문제이다.
Error creating bean with name 'chatController': Unsatisfied dependency expressed through field 'service';
Error creating bean with name 'chatRoomServiceImpl': Unsatisfied dependency expressed through field 'dao'
Error creating bean with name 'chatRoomDaoImpl': Unsatisfied dependency expressed through field 'session'
No qualifying bean of type 'org.apache.ibatis.session.SqlSession' available:
controller > service > dao > sql 로 발생하는 문제
1. 먼저 SQL 문법먼저 확인을 했다, DB 랑 비교해서 확인해보았고 실행해보았지만 문제없었다.
2. Dao 에 가서 @Repository 를 확인하고 sqlSession 을 살펴보았지만 문제가 없었다.
3. Service 에 가서 @Service 를 확인하고 비교해보았지만 문제가 없었다.
4. Controller 에 가서 매개변수와 인수를 확인하였지만 문제가 없었다.
5. sql 파일을 프로젝트 안에서 작동시켰는데 작동했다, sql 연결문제는 아니였다.
그런데 sql 에서 시작된 문제였다. 그래서 sql 부분을 확인해보았다.
[spring - applicationContext.xml ]
<!-- DB 설정파일 loading -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:properties/jdbc.properties</value>
</list>
</property>
</bean>
properties/jdbc.properties 를 확인해보았다. value 에 있는 경로에 문제는 없었다.
applicationContext.xml 을 읽는 web.xml 을 살펴보았다.
여기에서 문제를 발견했다. 바로 applicationContext.xml 에 해당 코드가 없었다.
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>