다중DB 관련질문입니다.
- 작성자 :
- 문*숙
- 작성일 :
- 2012-06-18 19:14:20
- 조회수 :
- 2,055
- 구분 :
- 개발환경
- 진행상태 :
- 완료
Q
다중 DB 설정 관련 하여 QNA 와 FAQ 에 이미 질문 되어 있던 것을 찿아 보았으나 에러가
생겨 질문을 올립니다.
다중 DB 설정 순서가
1. context-datasource.xml 추가 정의
2. context-sqlMap.xml 추가 정의 (context-datasource.xml 에서 설정 한 ID 값 사용)
3. AstractDAO 구현
이렇게 되어 있는데요,
우선 2까지 설정 하면
1. context-datasource.xml 에
<bean id="otherDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
...
...
중략
</bean>
추가 정의 했습니다.
2. context-sqlMap.xml
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocations" value="classpath:/ifez/sqlmap/sql-map-config.xml"/>
<property name="dataSource" ref="dataSource"/>
<property name="otherDataSource" ref="otherDataSource"/>
</bean>
otherDataSource 값을 추가 정의 하고 실행 해보면
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sqlMapClient' defined in ServletContext resource [/WEB-INF/config/spring/context-sqlMap.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'otherDataSource' of bean class [org.springframework.orm.ibatis.SqlMapClientFactoryBean]: Bean property 'otherDataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
검색 한 자료 에서는 이렇게 하라고 해서 설정 하고 테스트 했더니 계속 에러가 떨어 집니다. 이외 다른 .jar 파일을 넣어야 된다 던가 해야 하나요 ?
WAS 는 톰켓 사용 하고 있습니다. 우선은 WAS 와는 별개 인것 같은데요. 맞습니까?
그리고 마지막 AstractDAO 구현이라고 되어 있는데
public class OtherAbstractDAO extends EgovAbstractDAO {
@Resource(name="otherDataSource")
public void setSuperSqlMapClient(SqlMapClient sqlMapClient) {
// TODO Auto-generated method stub
super.setSuperSqlMapClient(sqlMapClient);
}
}
구현 하여
아래와 같이 사용 하면 되는지요???
@Repository("testDAO")
public class TestDAO extends OtherAbstractDAO {
public List testList(TestVO testVO) throws Exception {
// TODO Auto-generated method stub
return list("TestDAO.testList", testVO);
}
}
다중DB 사용 관련 해서 샘플 자료 을 보고 싶습니다.
생겨 질문을 올립니다.
다중 DB 설정 순서가
1. context-datasource.xml 추가 정의
2. context-sqlMap.xml 추가 정의 (context-datasource.xml 에서 설정 한 ID 값 사용)
3. AstractDAO 구현
이렇게 되어 있는데요,
우선 2까지 설정 하면
1. context-datasource.xml 에
<bean id="otherDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
...
...
중략
</bean>
추가 정의 했습니다.
2. context-sqlMap.xml
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocations" value="classpath:/ifez/sqlmap/sql-map-config.xml"/>
<property name="dataSource" ref="dataSource"/>
<property name="otherDataSource" ref="otherDataSource"/>
</bean>
otherDataSource 값을 추가 정의 하고 실행 해보면
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sqlMapClient' defined in ServletContext resource [/WEB-INF/config/spring/context-sqlMap.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'otherDataSource' of bean class [org.springframework.orm.ibatis.SqlMapClientFactoryBean]: Bean property 'otherDataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
검색 한 자료 에서는 이렇게 하라고 해서 설정 하고 테스트 했더니 계속 에러가 떨어 집니다. 이외 다른 .jar 파일을 넣어야 된다 던가 해야 하나요 ?
WAS 는 톰켓 사용 하고 있습니다. 우선은 WAS 와는 별개 인것 같은데요. 맞습니까?
그리고 마지막 AstractDAO 구현이라고 되어 있는데
public class OtherAbstractDAO extends EgovAbstractDAO {
@Resource(name="otherDataSource")
public void setSuperSqlMapClient(SqlMapClient sqlMapClient) {
// TODO Auto-generated method stub
super.setSuperSqlMapClient(sqlMapClient);
}
}
구현 하여
아래와 같이 사용 하면 되는지요???
@Repository("testDAO")
public class TestDAO extends OtherAbstractDAO {
public List testList(TestVO testVO) throws Exception {
// TODO Auto-generated method stub
return list("TestDAO.testList", testVO);
}
}
다중DB 사용 관련 해서 샘플 자료 을 보고 싶습니다.
A
안녕하세요.. 문진숙님..
추가된 sqlMapClient에서... 2가지 정보를 다음과 같이 변경하세요..
<bean id="otherSqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocations" value="classpath:/ifez/sqlmap/sql-map-config.xml"/>
<property name="dataSource" ref="dataSource"/>
<property name="dataSource" ref="otherDataSource"/>
</bean>
SqlMapClient가 실제 가지고 있는 property는 dataSource입니다. 그 dataSource에 추가된 otherDataSource를 injection하는 것입니다.
다음으로.. OtherAbstractDAO 소스에서.. @Resource로 injection하는 것은.. dataSource가 아니 위에서 추가된 otherSqlMapClient입니다.
public class OtherAbstractDAO extends EgovAbstractDAO {
@Resource(name="otherSqlMapClient")
public void setSuperSqlMapClient(SqlMapClient sqlMapClient) {
..
해당 소스는 자료실에 있는 "기술지원용 template 프로젝트"를 참조하시면 됩니다.
그럼.. 즐거운 하루되십시오.
감사합니다.
추가된 sqlMapClient에서... 2가지 정보를 다음과 같이 변경하세요..
<bean id="otherSqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocations" value="classpath:/ifez/sqlmap/sql-map-config.xml"/>
<property name="dataSource" ref="dataSource"/>
<property name="dataSource" ref="otherDataSource"/>
</bean>
SqlMapClient가 실제 가지고 있는 property는 dataSource입니다. 그 dataSource에 추가된 otherDataSource를 injection하는 것입니다.
다음으로.. OtherAbstractDAO 소스에서.. @Resource로 injection하는 것은.. dataSource가 아니 위에서 추가된 otherSqlMapClient입니다.
public class OtherAbstractDAO extends EgovAbstractDAO {
@Resource(name="otherSqlMapClient")
public void setSuperSqlMapClient(SqlMapClient sqlMapClient) {
..
해당 소스는 자료실에 있는 "기술지원용 template 프로젝트"를 참조하시면 됩니다.
그럼.. 즐거운 하루되십시오.
감사합니다.