0

When I was using spring MVC, its annotation features is very difference between XML way. It seems can be more convenient and efficient. BUT, HOW TO INJECT a number of properties into a number of bean made me feel confused.

As all we know, in XML way, it was very clear as below.

${"xxx.xxx.key:default"}

also, the spel is equivalent to @Value.

but, with @Value, there are too many global field need to be defined in a bean. So, how to avoid it? or a better practice? I have tried PropertyOverrideConfigurer, but beanname.field is not a better choice for me?

Vincent
  • 13
  • 5
  • If you have 10 xml values you also need 10 `@Value` those should translate 1-on-1... I don't really see the difference... – M. Deinum Jun 01 '16 at 10:18
  • yeah, image that if there are over 100 values need to be injected, how UGLY the code will be. – Vincent Jun 01 '16 at 12:16
  • Then your XML would be as ugly, only difference it would be externalized. – M. Deinum Jun 01 '16 at 12:24
  • 1
    Create property beans which contain multiple numbers of properties and inject those property beans to your services – Ali Dehghani Jun 01 '16 at 12:25
  • 1
    Which is also the approach that spring Boot takes (I suggest a look on that). – M. Deinum Jun 01 '16 at 12:26
  • @M.Deinum No, I don't think the XML way would be ugly, as we don't really need to declare fields which were already declared in your bean. – Vincent Jun 02 '16 at 01:58
  • @AliDehghani yes, create property bean could solved this issues, but I don't think it was a better practice for me because it had a strong association with the bean id(name) – Vincent Jun 02 '16 at 02:07

0 Answers0