Spring @Autowired usage

后端 未结 9 806
长发绾君心
长发绾君心 2020-12-04 04:51

What are the pros and cons of using @Autowired in a class that will be wired up by Spring?

Just to clarify, I\'m talking specifically about the

9条回答
  •  情深已故
    2020-12-04 05:05

    There has been very little discussion about switching environments. Most projects I've worked on it was a real issue to inject dependencies depending on the environment we are working on. With xml config it's pretty straightforward with Spring EL, and I am not aware of any nice solution with annotations. I've just figured out one:

        @Value("#{${env} == "production" ? realService : dummyService}")
        private SomeService service;
    

    It should be working, but not a nice solution imho.

提交回复
热议问题