# @Value
- DaoImpl
@SuppressWarnings("all") | |
@Repository("bookDao1") | |
public class BookDaoImpl implements BookDao { | |
@Value("刘桑") | |
private String name; | |
public void save(){ | |
System.out.println("BookDaoImpl save rning..."+","+name); | |
} | |
} |
- ServiceImpl
@SuppressWarnings("all") | |
@Service("bookService") | |
public class BookServiceImpl implements BookService { | |
@Autowired | |
@Qualifier("bookDao1") | |
private BookDao bookDao; | |
public void save(){ | |
System.out.println("BookServiceImpl save rning..."); | |
bookDao.save(); | |
} | |
} |
- Test
public void test(){ | |
ApplicationContext c = new AnnotationConfigApplicationContext(SpringConfig.class); | |
BookService service = c.getBean("bookService",BookService.class); | |
service.save(); | |
} |
Run Result