Skip to content

Instantly share code, notes, and snippets.

@rcaneppele
Created May 29, 2014 16:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcaneppele/4b0e117754ad94aa1c97 to your computer and use it in GitHub Desktop.
Save rcaneppele/4b0e117754ad94aa1c97 to your computer and use it in GitHub Desktop.
FJ21-Tarefas - Multiplos Datasources
@Repository
public class JdbcTarefaDao
private Connection connection;
@Autowired
@Qualifier("postgreDataSource")
private DataSource dataSource;
@PostConstruct
public void init() {
try {
this.connection = dataSource.getConnection();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
//métodos
}
<bean id="mysqlDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost/fj21"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
<bean id="postgreDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://localhost/fj21"/>
<property name="username" value="postgres"/>
<property name="password" value="postgres"/>
</bean>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment