This repository has been archived by the owner on Mar 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
itning
committed
Mar 14, 2019
1 parent
050baf8
commit bcec319
Showing
7 changed files
with
87 additions
and
10 deletions.
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
src/main/java/top/yunshu/shw/server/config/SpringContextHelper.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package top.yunshu.shw.server.config; | ||
|
||
import org.springframework.beans.BeansException; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @author itning | ||
*/ | ||
@Component | ||
public class SpringContextHelper implements ApplicationContextAware { | ||
|
||
private static ApplicationContext applicationContext; | ||
|
||
@Override | ||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
if (SpringContextHelper.applicationContext == null) { | ||
SpringContextHelper.applicationContext = applicationContext; | ||
} | ||
} | ||
|
||
public static ApplicationContext getApplicationContext() { | ||
return applicationContext; | ||
} | ||
|
||
public static Object getBean(String name) { | ||
return getApplicationContext().getBean(name); | ||
} | ||
|
||
public static <T> T getBean(Class<T> clazz) { | ||
return getApplicationContext().getBean(clazz); | ||
} | ||
|
||
public static <T> T getBean(String name, Class<T> clazz) { | ||
return getApplicationContext().getBean(name, clazz); | ||
} | ||
} |
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
Binary file not shown.
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