I can not understand what Bean is in Wikipedia, it is written as just a domain object, there are still services, controllers, DAO, which of them is a bin and why is it called that I do not understand?

2 answers 2

In Spring, bean is any class that is controlled by a Spring container. That is, such things as instantiating a bean, initializing it, introducing dependencies and parameters, deinitializing, generating all sorts of wrappers over a bin are not your code, but the Spring IoC container.

  • It turns out, and the service and domain and controller are bin? - J Mas
  • 2
    If they hang out in a spring container, they are spring bins . - Nofate

Well, in essence, this is a class with some limitations. 1) The constructor is used without parameters. 2) All fields are private with access via a getter and setter.

  • Why I declare the service as a bin <bean id = "myUserDetailsService" class = "kz.tanikin.springtest.service.MyUserDetailsService" /> why not the domain object is not declared, why it is declared - J Mas
  • Neither the first nor the second is wrong. A constructor can be used. Private fields can be injected when using auto-typing. - a_gura