mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
commit
2031e17195
@ -0,0 +1,19 @@
|
|||||||
|
package cn.hutool.extra.spring;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启用SpringUtil, 即注入SpringUtil到容器中
|
||||||
|
*
|
||||||
|
* @author sidian
|
||||||
|
*/
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Import(SpringUtil.class)
|
||||||
|
public @interface EnableSpringUtil {
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package cn.hutool.extra.spring;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sidian
|
||||||
|
*/
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest(classes = EnableSprintUtilTest.class)
|
||||||
|
@EnableSpringUtil
|
||||||
|
public class EnableSprintUtilTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
// 使用@EnableSpringUtil注解后, 能获取上下文
|
||||||
|
Assert.assertNotNull(SpringUtil.getApplicationContext());
|
||||||
|
// 不使用时, 为null
|
||||||
|
// Assert.assertNull(SpringUtil.getApplicationContext());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user