1

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.

ase
  • 13,231
  • 4
  • 34
  • 46
Santosh Pandey
  • 190
  • 1
  • 1
  • 10

1 Answers1

2

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");
e2rabi
  • 4,728
  • 9
  • 42
  • 69
  • Suppose that I have to use same bean in other class also. again i have to call application context interface reference. i think its not good idea for web application. its ok for standalone apllication so please tell other solution. – Santosh Pandey Feb 06 '17 at 04:05