Difference between Spring annotations

前端 未结 5 1513
说谎
说谎 2020-12-04 11:08

Questions:

1) Difference between @Component and @Configuration?

I have read that both remove the necessity of

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 11:49

    1) If you want XML configuration, then ignore @Configuration, as this is only useful for Java-based config. XML config is probably best for someone unfamiliar with Spring as there are more examples available.

    @Component annotated classes are picked up during component scanning. Use them to label classes that you want to expose as Spring beans. Again, you can just declare all of your beans in the XML config and ignore @Component altogether.

    2) If you are happy to tie your application to Spring, then use @Autowire rather than the javax equivalent @Inject. I'd suggest that accepting a dependency to Spring is the best way to start.

提交回复
热议问题