This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ch01] Use DataSource to get connection.
- Loading branch information
Showing
4 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
package ch01.springbook.user.dao; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.jdbc.datasource.SimpleDriverDataSource; | ||
|
||
@Configuration | ||
public class DaoFactory { | ||
|
||
@Bean | ||
public UserDao userDao() { | ||
return new UserDao(connectionMaker()); | ||
UserDao userDao = new UserDao(); | ||
userDao.setDataSource(dataSource()); | ||
return userDao; | ||
} | ||
|
||
@Bean | ||
public ConnectionMaker connectionMaker() { | ||
return new SimpleConnectionMaker(); | ||
} | ||
|
||
@Bean | ||
public DataSource dataSource() { | ||
SimpleDriverDataSource simpleDriverDataSource = new SimpleDriverDataSource(); | ||
|
||
simpleDriverDataSource.setDriverClass(com.mysql.jdbc.Driver.class); | ||
simpleDriverDataSource.setUrl("jdbc:mysql://localhost/tobystudy?useUnicode=true&characterEncoding=UTF-8&useSSL=true&verifyServerCertificate=false"); | ||
simpleDriverDataSource.setUsername("study"); | ||
simpleDriverDataSource.setPassword("study"); | ||
|
||
return simpleDriverDataSource; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters