Here is config.xml:
config.xml file:
Here I’m using 2 datasources as spring jdbc and hikariCP.
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value="org.postgresql.Driver"></property>
<property name="url" value="jdbc:postgresql://localhost:5432/spring_db"></property>
<property name="username" value="postgres"></property>
<property name="password" value="root"></property>
</bean>
<!-- Third paty datasource -->
<bean id="hikariDs" class="com.zaxxer.hikari.HikariDataSource"
primary="false">
<property name="driverClassName"
value="org.postgresql.Driver"></property>
<property name="jdbcUrl"
value="jdbc:postgresql://localhost:5432/spring_db" />
<property name="username" value="postgres"></property>
<property name="password" value="root"></property>
</bean>
CustomerDaoImpl.Class file:
public class CustomerDaoImpl implements CustomerDao {
@Autowired
@Qualifier("hikariDs")
private DataSource dataSource;
}
Here i’m trying to autowire datasource, but since there are 2 beans in xml file with same type, so byType annotation fails, so i’ve used @Qualifier and mentioned name of bean to be inject.
But its giving me an Exception saying NoUniqueBeanFound : expected 1 found 2 datasource, hikariDs
Satvik is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.