java - questions on Spring @Autowired and Spring JDBC -


i had questions.

  1. in case @autowired not preferable?
  2. in scenario, have prefer spring-jdbc spring-hibernate?
  3. what happens if autowire objects?

please me on questions

1. in case @autowired not preferable?

autowiring simplifying dependency injections. may seems easy , lucrative @ first later realize not maintainable in big real-life projects.

default autowiring in spring by-type. not prefer when have more 1 instance of particular class , have force spring resolve injections by-name , have use additional @qualifier. prefer going javax @resource in such cases.

also, might face situation have create , inject beans based on properties/arguments. in such cases @autowired might not work , might have opt xml based configuration.

2. in scenario, have prefer spring-jdbc spring-hibernate?

the choice of selection between jdbc vs hibernate depends on project , how think can accommodate hibernate. both these implementations fast indeed. both of these have own advantages , disadvantages.

using spring's jdbctemplate bit easier wrapper around native jdbc itself. thing here might end in writing thousands of lines of code can hard maintain once project starts growing.

using hibernate result in cleaner , simpler code easy maintain overhead here can learn hibernate , think in way make fit project.

3. happens if autowire objects?

it depends on project needs. @autowire used inject dependencies. there situation encounter more 1 instance of particular class , in such cases avoid using @qualifier @autowired remove ambiguity have choice replace 2 annotations single annotation @resource.

also, you'll find better inject dependency beans via xml based configuration rather using @autowired.

there no harm if autowiring classes. said before depends on project needs.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -