Configuration metadata in Spring Framework

0 votes

How do I provide configuration metadata to the Spring container?

Aug 2, 2018 in Java by anto.trigg4
• 3,420 points
516 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Configuration metadata can be provided to Spring container in following ways:

  • XML-Based configuration: In Spring Framework, the dependencies and the services needed by beans are specified in configuration files which are in XML format. These configuration files usually contain a lot of bean definitions and application-specific configuration options. They generally start with a bean tag. For example:

<bean id="studentbean" class="org.edureka.firstSpring.StudentBean">
<property name="name" value="Edureka"></property>
</bean>
  • Annotation-Based configuration: Instead of using XML to describe a bean wiring, you can configure the bean into the component class itself by using annotations on the relevant class, method, or field declaration. By default, annotation wiring is not turned on in the Spring container. So, you need to enable it in your Spring configuration file before using it. For example:
<beans>
<context:annotation-config/>
<!-- bean definitions go here -->
</beans>
  • Java-based configuration: The key features in Spring Framework’s new Java-configuration support are @Configuration annotated classes and @Bean annotated methods. 

1. @Bean annotation plays the same role as the <bean/> element. 

2.@Configuration classes allow define inter-bean dependencies by simply calling other @Bean methods in the same class.

For example:

@Configuration
public class StudentConfig
{
@Bean
public StudentBean myStudent()
{ return new StudentBean(); }
}
answered Aug 2, 2018 by code.reaper12
• 3,450 points

Related Questions In Java

0 votes
1 answer

@Component vs @Repository vs @Service in Spring Framework

As you might be knowing, all these ...READ MORE

answered May 29, 2018 in Java by geek.erkami
• 2,320 points
580 views
0 votes
1 answer

Constructor injection vs Setter injection in Spring Framework

Here, I have listed down few differences. ...READ MORE

answered Aug 29, 2018 in Java by anto.trigg4
• 3,420 points
187 views
0 votes
1 answer

Autowired field pointing NULL in Spring

The field annotated @Autowired is null because ...READ MORE

answered Jun 6, 2018 in Java by avi
• 160 points
3,101 views
0 votes
1 answer

Annotation wiring in Spring

By default, Annotation wiring is not turned ...READ MORE

answered Jul 3, 2018 in Java by code.reaper12
• 3,450 points
50 views
0 votes
1 answer

@Autowired annotation in Spring Framework

The @Autowired annotation provides more accurate control over where ...READ MORE

answered Aug 2, 2018 in Java by geek.erkami
• 2,320 points
78 views
0 votes
1 answer

Types of IOC containers in Spring Framework

There are basically two types of IOC ...READ MORE

answered Aug 27, 2018 in Java by misc.edu04
• 1,380 points
106 views
0 votes
1 answer

Types of transaction management in Spring Framework

Well there are basically to types of ...READ MORE

answered Nov 27, 2018 in Java by geek.erkami
• 2,320 points
148 views
0 votes
1 answer

Spring configuration file

A Spring configuration file is an XML ...READ MORE

answered Aug 27, 2018 in Java by v.liyyah
• 1,290 points
16 views
0 votes
1 answer
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.