Surendran Duraisamy
Surendran Duraisamy

Reputation: 2531

Avoid applicationContext.xml in my Action and Service Classes

I am writing a web application using Struts, Spring framework. In the Struts Action I am Injecting Service Classes as follows

    ApplicationContext context =
            new ClassPathXmlApplicationContext("applicationContext.xml");
    loginService = (LoginService)context.getBean("loginService");

How can I avoid mentioning applicationContext.xml in my Action classes I just have to use loginService = (LoginService)context.getBean("loginService"); without specifying the .xml file in my class.

I came across to use below while googling

private LoginService loginService = (LoginService)ApplicationContextProvider.getContext().getBean("loginService");

But I do not want to use static method getContext().

Upvotes: 0

Views: 294

Answers (1)

ndeverge
ndeverge

Reputation: 21564

Spring support Struts integration in the package org.springframework.web.struts.

Take a look at this article for an example.

Upvotes: 2

Related Questions