3

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.

1 Answer 1

3

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.