com.sinszm.common.SpringContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of szm-boot-common Show documentation
Show all versions of szm-boot-common Show documentation
基于SpringBoot扩展生态应用公共组件
Copyright © 2020 智慧程序猿 All rights reserved.
https://www.sinsz.com
package com.sinszm.common;
import org.springframework.context.ApplicationContext;
/**
* 实例读取器
*
* @author chenjianbo
*/
public final class SpringContext {
private ApplicationContext applicationContext = null;
private static class Spring {
private static SpringContext holder = new SpringContext();
}
private SpringContext() {
}
public static SpringContext instance() {
return Spring.holder;
}
void init(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
private void check() {
assert this.applicationContext != null;
}
public ApplicationContext context() {
check();
return this.applicationContext;
}
public T getBean(Class clazz){
check();
return context().getBean(clazz);
}
public Object getBean(String name){
check();
return context().getBean(name);
}
public T getBean(String name,Class clazz){
check();
return context().getBean(name, clazz);
}
public String activeProfile() {
return context().getEnvironment().getActiveProfiles()[0];
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy