我有一個spring.xml文件,其中列出了所有bean定義,其中列出了所有使用bean,指定messageSource,dataSource等的依賴關係。另外,我有一個類ApplicationContext類,其中iam使用上下文獲取所有豆。 的代碼::在Spring MVC中使用ApplicationContext。
package models;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class ApplicationContextClass {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
AbstractApplicationContext context = new ClassPathXmlApplicationContext("Spring.xml");
context.registerShutdownHook();
ATTModel attmodel = (ATTModel) context.getBean("att");
//ProjectModel project = (ProjectModel)context.getBean("project");
//project.call1();
attmodel.call();
System.out.println(context.getMessage("insertiondone",null, "Default greeting",null));
}
}
,我有其中一個ApplicationContext用於訪問的JdbcTemplate相關Bean DAO類。我必須現在使用spring MVC開發一個web應用程序,並且我需要使用這個applicationContext。我如何在SpringMVC中使用這些applicationContext類。我knw我需要使用applicationcontextlisteners但寫在哪裏?謝謝..