I've looked over the documentation to define a bean. I'm just unclear on what class file to use for a Mysql database. Can anyone fill in the bean definition below?
<bean name="dataSource" class="">
<property name="driverClassName" value="" />
<property name="url" value="mysql://localhost/GameManager" />
<property name="username" value="gamemanagertest" />
<property name="password" value="1" />
</bean>
So if you want to refer a bean created in Java class in an XML file, simply use ref= beanName attribute to refer the bean and vice versa. To declare a bean, simply annotate a method with the @Bean annotation.
To configure your own DataSource , define a @Bean of that type in your configuration. Spring Boot reuses your DataSource anywhere one is required, including database initialization. If you need to externalize some settings, you can bind your DataSource to the environment (see “Section 25.8.
In XMLbased configuration metadata, you use the id and/or name attributes to specify the bean identifier(s). This attribute specifies the scope of the objects created from a particular bean definition and it will be discussed in bean scopes chapter.
<bean name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/GameManager" />
<property name="username" value="gamemanagertest" />
<property name="password" value="1" />
</bean>
http://docs.spring.io/spring-data/jdbc/docs/1.1.0.M1/reference/html/orcl.datasource.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With