Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i get my Application Context in xml defination while working in Spring Boot

Tags:

java

spring

What is the xml equivalent of the

@Autowired
private ApplicationContext appContext;
?

P.S.: When I try to google it I got a million results about how ApplicationContext works but not how to get it in the xml definition. The project is all writen using xml definition so I need to find a way how to do it without anotations.

like image 364
Mohammad Avatar asked May 18 '26 18:05

Mohammad


1 Answers

First, configure your spring beans in file applicationContext.xml For example:-

        <bean id="beanId"
         class="com.java.spring.MyClassName">
        </bean>

load the spring configuration file and retrieve bean from spring container

        ClassPathXmlApplicationContext context = 
                     new ClassPathXmlApplicationContext("applicationContext.xml");
        
        MyClass myBean = context.getBean("beanId",MyClass.class);
like image 198
Sourabh Kundu Avatar answered May 20 '26 07:05

Sourabh Kundu