Zeus
Zeus

Reputation: 6566

Use spring datasource of maven application within its dependency

I'm planning to build a library using spring and use it as an mvn dependency. The library would be used as an api in several projects. The api does only database operations. Can the included dependency get the datasource/jdbcTemplate of the project it is included in as an Autowired spring bean?

the datasource/jdbctemplate that we use in the spring application context is like following

<bean id="JdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <constructor-arg index="0" type="javax.sql.DataSource" ref="dataSource" />
</bean>

Upvotes: 1

Views: 908

Answers (1)

UserF40
UserF40

Reputation: 3611

Yes. As long as there is a been with the name datasource and class javax.sql.DataSource. It needs to be available either through configuration, XML wiring or component scanning.

If creating a new library API it would be good to document what the user needs to make available for wiring.

Upvotes: 1

Related Questions