1 package de.spring.example;
3 import org.springframework.context.ApplicationContext;
4 import org.springframework.context.support.ClassPathXmlApplicationContext;
8 * Localizador de beans para de los dispositivos
12 public final class SpringContextLocator {
16 private static SpringContextLocator instance;
18 // Spring ApplicationContext
19 private static ApplicationContext context;
21 // Dispositivos logicos
22 private static final String SPRING_CONFIG_CONTEXT="spring-config.xml";
23 //private static final String DATABASE_CONFIG="database-config.xml";
27 * Private constructor. Singleton pattern.
29 private SpringContextLocator() {
30 String[] factoryFiles = null;
31 System.out.println("Loading files context " +
32 SpringContextLocator.SPRING_CONFIG_CONTEXT);
34 factoryFiles = new String[] { SPRING_CONFIG_CONTEXT };
36 SpringContextLocator.context = new ClassPathXmlApplicationContext(factoryFiles);
38 System.out.println("The N2A devices context and test " +
39 "context has been loaded successfully!! ");
43 * Singleton pattern. GetInstance()
45 public synchronized static SpringContextLocator getInstance() {
46 if (SpringContextLocator.instance == null) {
47 SpringContextLocator.instance = new SpringContextLocator();
49 return SpringContextLocator.instance;
53 * Return a bean in application context.
55 public Object getBean(final String name) {
56 return SpringContextLocator.context.getBean(name);