1 package de.remote.agents.clients.app;
3 import org.apache.log4j.Logger;
4 import org.springframework.context.ApplicationContext;
5 import org.springframework.context.support.ClassPathXmlApplicationContext;
7 public class SpringContextLocator {
8 private static final Logger logger = Logger.getLogger(SpringContextLocator.class);
11 private static SpringContextLocator instance;
13 // Spring ApplicationContext
14 private static ApplicationContext context;
17 private static final String SPRING_CONFIG_CONTEXT = "clients-remote-agents-spring.xml";
20 * Private constructor. Singleton pattern.
22 private SpringContextLocator() {
23 logger.info("Loading context files: " + SpringContextLocator.SPRING_CONFIG_CONTEXT);
25 final String[] factoryFiles = new String[] { SPRING_CONFIG_CONTEXT };
27 context = new ClassPathXmlApplicationContext(factoryFiles);
29 logger.info("The context has been loaded successfully!! ");
33 * Singleton pattern not thread safety. To use SingletoHolder pattern as the
34 * best approximation otherwise to use an Enum class (see Effective Java
35 * Second Edition and ) if we need serialization.
37 public static SpringContextLocator getInstance() {
38 if (instance == null) {
39 instance = new SpringContextLocator();
45 * Return bean from application context.
47 public Object getBean(final String name) {
48 return context.getBean(name);