Spring Autowire Fundamentals

后端 未结 2 2071
南笙
南笙 2021-02-09 07:32

I am a newbie in Spring and am trying to understand the below concept.

Assume that accountDAO is a dependency of AccountService.

Scenar

2条回答
  •  我寻月下人不归
    2021-02-09 08:30

    Use @Component and @Autowire, it's the Spring 3.0 way

    @Component
    public class AccountService {
        @Autowired
        private AccountDAO accountDAO;
        /* ... */
    }   
    

    Put a component scan in your app context rather than declare the beans directly.

    
    
    
        
    
    
    

提交回复
热议问题