Skip to content

BhaskarMantralaHub/spring-boot-foundation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

spring-boot-foundation

Beans

Get class objects (Singleton) from two containers:

  1. Application Context
  2. Bean Factory

Application context extends Bean factory.

Application Context:

From resources/.xml file

XML file
<beans>
//class with no properties
<bean class="classpath" id="uniqueID"> </bean>

//class with properties
//Property or class variables
<bean class="classpath" id="classWithProperties">
<property name="propertyName" value="propertyValue"></property>
</bean>

//class with properties and constructor
<bean class="classpath" id="classWithProperties">
<constructor-arg value="propertyValue"></constructor-arg>
</bean>

//class with property as another class
<bean class="classpath" id="classWithProperties">
<property name="propertyObjectName" ref="classObjectBeanUniqueID"></property>
</bean>
</beans>


ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
ClassName className = context.getBean(ClassName.class);
(OR)
ClassName className = (ClassName) context.getBean("uniqueID")

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages