Why does Spring's @Configurable sometimes work and sometimes not?

前端 未结 6 1515
感情败类
感情败类 2020-12-16 18:05

I\'m trying to use automatic dependency injection via Spring\'s @Configurable annotation w/ @Resource on the fields needing injection. This involved some setup, like passing

6条回答
  •  [愿得一人]
    2020-12-16 18:55

    First I have to say that it is probably not a good idea to have resources, services or other beans injected into data model classes as dependencies. But that is a question of design.

    To the usage of @Configurable I used it in cases where objects are instantiated from outside the Spring context - like custom tags in web applications, filters or servlets. The first way I tried to use them was by load time weaving like you do. That worked quite well but it had some drawbacks like hot code deployment while debugging did not work anymore.

    I did also experience exactly the problem you describe and so I decided to switch from load time weaving to compile time. Therefor I installed the AJDT plugin in Eclipse and used the aspecjt support of Spring. That solved my problems.

提交回复
热议问题