Skip to content

Integration with Spring

見える edited this page May 4, 2022 · 2 revisions

Spring XML

<bean id="mysqlDS" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName">com.mysql.jdbc.Driver</property>
    <property name="url">jdbc:mysql://localhost:3306/testDB</property>
    <property name="username">user</property>
    <property name="password">pass</property>
</bean>
<bean id="anima" class="com.hellokaton.anima.Anima">
    <constructor-arg index="0" ref="mysqlDS"/>
</bean>

Spring Boot

@Autowired
private DataSource dataSource;

@Bean
public Anima anima(){
    return new Anima(dataSource);
}