Skip to content

Commit 8225290

Browse files
committed
增加ApplicationContextHolder
1 parent 11e011d commit 8225290

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

hsweb-commons/hsweb-commons-utils/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
<optional>true</optional>
3939
</dependency>
4040

41+
<dependency>
42+
<groupId>org.springframework</groupId>
43+
<artifactId>spring-context</artifactId>
44+
<optional>true</optional>
45+
</dependency>
46+
4147
<dependency>
4248
<groupId>org.aspectj</groupId>
4349
<artifactId>aspectjweaver</artifactId>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.hswebframework.web;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.context.ApplicationContext;
5+
import org.springframework.stereotype.Component;
6+
7+
/**
8+
* TODO 完成注释
9+
*
10+
* @author zhouhao
11+
*/
12+
@Component
13+
public class ApplicationContextHolder {
14+
private static ApplicationContext context;
15+
16+
public static final ApplicationContext get() {
17+
if (null == context) {
18+
throw new UnsupportedOperationException("ApplicationContext not ready!");
19+
}
20+
return context;
21+
}
22+
23+
@Autowired
24+
public void setContext(ApplicationContext context) {
25+
if (null == ApplicationContextHolder.context)
26+
ApplicationContextHolder.context = context;
27+
}
28+
}

0 commit comments

Comments
 (0)