package index.context;
import java.util.Properties;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;
public enum Application {
LunceneIndexer;
Properties props;
private ClassPathXmlApplicationContext applicationContext;
void setProps(Properties props) {
this.props = props;
}
void loadApplication() {
applicationContext = new ClassPathXmlApplicationContext("maven-lucene-context.xml");
applicationContext.start();
}
public <T> T getInstance(Class<T> objectType) {
T contextBean = applicationContext.getBean(objectType);
return contextBean;
}
}
@Component
class RegisterProperties {
@Bean
PropertyPlaceholderConfigurer register() {
PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
configurer.setProperties(Application.LunceneIndexer.props);
return configurer;
}
}