パッケージcom.example.ssm.util。 輸入org.springframework.beans.BeansException。 輸入org.springframework.context.ApplicationContext; 輸入org.springframework.context.ApplicationContextAware。 輸入org.springframework.stereotype.Component。 @Component パブリッククラスSpringContextUtilはApplicationContextAware {実装 プライベート静的のApplicationContextのApplicationContext =ヌル; @Override 公共ボイドsetApplicationContext(ApplicationContextのApplicationContextの)はBeansExceptionをスロー{ this.applicationContext =のApplicationContext。 } パブリック静的ApplicationContextのgetApplicationContext(){ ApplicationContextのを返します。 } パブリック静的オブジェクトgetBean(文字列のbeanName){ applicationContext.getBean(のbeanName)を返します。 } パブリック静的オブジェクトgetBean(クラスC){ applicationContext.getBean(c)を返します。 } }