Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change init of spring applicationContext
- Loading branch information
Showing
7 changed files
with
37 additions
and
45 deletions.
There are no files selected for viewing
25 changes: 14 additions & 11 deletions
25
sigla-ejb/src/main/java/it/cnr/contab/service/SpringUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
package it.cnr.contab.service; | ||
|
||
import org.springframework.beans.BeansException; | ||
import org.springframework.beans.factory.BeanFactory; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
import org.springframework.context.support.ClassPathXmlApplicationContext; | ||
import org.springframework.stereotype.Component; | ||
|
||
public final class SpringUtil { | ||
private static BeanFactory beanFactory; | ||
|
||
static { | ||
ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( | ||
new String[] {"it/cnr/contab/service/sigla-service-context.xml"}); | ||
beanFactory = (BeanFactory) appContext; | ||
} | ||
@Component | ||
public class SpringUtil implements ApplicationContextAware{ | ||
private static ApplicationContext CONTEXT; | ||
|
||
public static <T extends Object> T getBean(String beanName, Class<T> clazz){ | ||
return (T) beanFactory.getBean(beanName, clazz); | ||
return (T) CONTEXT.getBean(beanName, clazz); | ||
} | ||
|
||
public static <T extends Object> T getBean(Class<T> clazz){ | ||
return (T) beanFactory.getBean(clazz); | ||
return (T) CONTEXT.getBean(clazz); | ||
} | ||
public static boolean containsBean(String name) { | ||
return beanFactory.containsBean(name); | ||
return CONTEXT.containsBean(name); | ||
} | ||
|
||
@Override | ||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
CONTEXT = applicationContext; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters