ways to add properties to Bean Spring
To add properties to a Bean in Spring, you can use the following ways:
- Using XML Configuration:
- Define the bean in the XML configuration file.
- Use the
tag to set properties of the bean. Specify the name of the property using the "name" attribute and the value using the "value" attribute.
Using Annotation:
- Annotate the class with @Component or other stereotype annotations.
Use @Value annotation to inject values from properties files or environment variables.
Using Java Configuration:
- Create a configuration class annotated with @Configuration.
- 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.