ways to add properties to Bean Spring

To add properties to a Bean in Spring, you can use the following ways:

  1. Using XML Configuration:
  2. Define the bean in the XML configuration file.
  3. Use the tag to set properties of the bean.
  4. Specify the name of the property using the "name" attribute and the value using the "value" attribute.

  5. Using Annotation:

  6. Annotate the class with @Component or other stereotype annotations.
  7. Use @Value annotation to inject values from properties files or environment variables.

  8. Using Java Configuration:

  9. Create a configuration class annotated with @Configuration.
  10. Use @Bean annotation to define the bean and set its properties using Java code.

Each of these methods provides a different approach to adding properties to a Bean in Spring, catering to different preferences and project requirements.