Santosh Pandey
Santosh Pandey

Reputation: 190

How to inject bean in controller without annotation in spring mvc

I am developing spring mvc web application. I want to inject a bean class inside controller or service class but I don't want to use any type of annotation.

Upvotes: 1

Views: 516

Answers (1)

e2rabi
e2rabi

Reputation: 4838

Define you bean in your appContext.xml or your bean config file

<bean id="mybean" class="MyClass"></bean>

And call your bean inside your controller using ApplicationContext interface :

ApplicationContext context = new FileSystemXmlApplicationContext("appContext.xml");

MyClass mybean= applicationContext.getBean("mybean");

Upvotes: 2

Related Questions