Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Define a MySql datasource bean via XML in Spring

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>
like image 759
cyotee doge Avatar asked Sep 29 '12 23:09

cyotee doge


People also ask

How bean is defined in XML configuration?

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.

How do you configure a DataSource in spring?

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.

Which XML element is used to define bean?

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.


1 Answers

<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

like image 63
cyotee doge Avatar answered Sep 19 '22 15:09

cyotee doge