Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
[ch07] Use @component / @componentscan
Browse files Browse the repository at this point in the history
  • Loading branch information
dhsim86 authored and Dongho Sim committed Oct 28, 2017
1 parent 4b7de1a commit e419f84
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
8 changes: 5 additions & 3 deletions src/main/java/ch01/springbook/user/UserServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ch01.springbook.user.dao.UserDao;
import ch01.springbook.user.domain.Level;
import ch01.springbook.user.domain.User;

/**
* Created by nhnent on 2017. 9. 7..
*/
@Service("userService")
public class UserServiceImpl implements UserService {

public static final int MIN_LOGCOUNT_FOR_SILVER = 50;
public static final int MIN_RECOMMEND_FOR_GOLD = 30;

@Autowired
private UserDao userDao;

public void setUserDao(UserDao userDao) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ch01/springbook/user/dao/UserDaoJdbc.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import ch01.springbook.user.domain.Level;
import ch01.springbook.user.domain.User;
import ch07.springbook.sql.SqlService;

@Repository
public class UserDaoJdbc implements UserDao {

@Autowired
Expand Down
22 changes: 7 additions & 15 deletions src/test/java/test/TestApplicationContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
Expand All @@ -16,10 +18,8 @@
import com.mysql.jdbc.Driver;

import ch01.springbook.user.UserService;
import ch01.springbook.user.UserServiceImpl;
import ch01.springbook.user.UserServiceTest;
import ch01.springbook.user.dao.UserDao;
import ch01.springbook.user.dao.UserDaoJdbc;
import ch06.springbook.factorybean.Message;
import ch06.springbook.factorybean.MessageFactoryBean;
import ch07.springbook.sql.OxmSqlService;
Expand All @@ -29,8 +29,12 @@

@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages = "ch01")
public class TestApplicationContext {

@Autowired
private UserDao userDao;

@Bean
public DataSource dataSource() {
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
Expand All @@ -49,22 +53,10 @@ public PlatformTransactionManager transactionManager() {
return transactionManager;
}

@Bean
public UserDao userDao() {
return new UserDaoJdbc();
}

@Bean
public UserService userService() {
UserServiceImpl userService = new UserServiceImpl();
userService.setUserDao(userDao());
return userService;
}

@Bean
public UserService testUserService() {
UserServiceTest.TestUserService testUserService = new UserServiceTest.TestUserService();
testUserService.setUserDao(userDao());
testUserService.setUserDao(userDao);
return testUserService;
}

Expand Down

0 comments on commit e419f84

Please sign in to comment.