다중 디비 연결
- 작성자 :
- 개*
- 작성일 :
- 2023-11-16 11:18:53
- 조회수 :
- 90
- 구분 :
- 개발환경 / 4.1
- 진행상태 :
- 완료
Q
안녕하세요
egov boot web 프로젝트로 환경만들고,
다중 디비 연결을위해 작업중인데,
현재 egovConfigMapper.java를 3개 만들어서 구조를 잡았구요
@Configuration
@MapperScan(basePackages = "spbt.cms.admin.service.impl")
public class EgovConfigMapper {
@Bean(name = "sqlSessionFactory")
public SqlSessionFactory sqlSessionFactory(@Qualifier("dataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
sqlSessionFactoryBean.setConfigLocation(new PathMatchingResourcePatternResolver().getResource("classpath:/spbt/sqlmap/sql-mapper-config.xml"));
sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:/spbt/sqlmap/mappers/admin/*.xml"));
return sqlSessionFactoryBean.getObject();
}
@Bean
public SqlSessionTemplate sqlSessionTemplate(@Qualifier("sqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
return new SqlSessionTemplate(sqlSessionFactory);
}
}
하나의 소스를 예를들자면 이렇게 만들었습니다.
@Qualifier 사용했고 been name도 다르게 했어요.
오류가 왜 나는 걸까요? 답변 부탁드립니다.
Description:
file [C:\Users\khwoo\git\repository\scms\target\classes\spbt\cms\admin\service\impl\AdmEDataMapper.class] required a single bean, but 3 were found:
- sqlSessionFactory: defined by method 'sqlSessionFactory' in class path resource [egovframework/example/config/EgovConfigSqlmap.class]
- flowerSqlSessionFactory: defined by method 'sqlSessionFactory' in class path resource [egovframework/example/config/EgovFlowerConfigMapper.class]
- ugilSqlSessionFactory: defined by method 'sqlSessionFactory' in class path resource [egovframework/example/config/EgovUgilConfigMapper.class]
Action:
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
egov boot web 프로젝트로 환경만들고,
다중 디비 연결을위해 작업중인데,
현재 egovConfigMapper.java를 3개 만들어서 구조를 잡았구요
@Configuration
@MapperScan(basePackages = "spbt.cms.admin.service.impl")
public class EgovConfigMapper {
@Bean(name = "sqlSessionFactory")
public SqlSessionFactory sqlSessionFactory(@Qualifier("dataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
sqlSessionFactoryBean.setConfigLocation(new PathMatchingResourcePatternResolver().getResource("classpath:/spbt/sqlmap/sql-mapper-config.xml"));
sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:/spbt/sqlmap/mappers/admin/*.xml"));
return sqlSessionFactoryBean.getObject();
}
@Bean
public SqlSessionTemplate sqlSessionTemplate(@Qualifier("sqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
return new SqlSessionTemplate(sqlSessionFactory);
}
}
하나의 소스를 예를들자면 이렇게 만들었습니다.
@Qualifier 사용했고 been name도 다르게 했어요.
오류가 왜 나는 걸까요? 답변 부탁드립니다.
Description:
file [C:\Users\khwoo\git\repository\scms\target\classes\spbt\cms\admin\service\impl\AdmEDataMapper.class] required a single bean, but 3 were found:
- sqlSessionFactory: defined by method 'sqlSessionFactory' in class path resource [egovframework/example/config/EgovConfigSqlmap.class]
- flowerSqlSessionFactory: defined by method 'sqlSessionFactory' in class path resource [egovframework/example/config/EgovFlowerConfigMapper.class]
- ugilSqlSessionFactory: defined by method 'sqlSessionFactory' in class path resource [egovframework/example/config/EgovUgilConfigMapper.class]
Action:
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
환경정보
-
- OS 정보 :
- 표준프레임워크 버전 : 4.1
- JDK(JRE) 정보 : 11
- WAS 정보 :
- DB 정보 :
- 기타 환경 정보 :
A
안녕하세요.
표준프레임워크센터입니다.
오류메시지는 같은 타입의 빈이 여러 개 있을 경우
@Autowired로 의존성을 주입받을 때 발생합니다.
남겨주신 오류메시지로만 보면
AdmEDataMapper 클래스에서 @Autowired로
의존성을 주입받은 것으로 보이므로
해당 클래스의 의존성 주입 부분을
확인해보시기 바랍니다.
감사합니다.
표준프레임워크센터입니다.
오류메시지는 같은 타입의 빈이 여러 개 있을 경우
@Autowired로 의존성을 주입받을 때 발생합니다.
남겨주신 오류메시지로만 보면
AdmEDataMapper 클래스에서 @Autowired로
의존성을 주입받은 것으로 보이므로
해당 클래스의 의존성 주입 부분을
확인해보시기 바랍니다.
감사합니다.