V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  jaylee4869  ›  全部回复第 19 页 / 共 24 页
回复总数  475
1 ... 11  12  13  14  15  16  17  18  19  20 ... 24  
给你工具类:

```java

package com.utils;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
* 以静态变量保存 Spring ApplicationContext, 可在任何代码任何地方任何时候中取出 ApplicaitonContext.
*
*/
public class SpringContextHolder implements ApplicationContextAware {
private static ApplicationContext applicationContext;

/**
* 实现 ApplicationContextAware 接口的 context 注入函数, 将其存入静态变量.
*/
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
// NOSONAR
SpringContextHolder.applicationContext = applicationContext;
}

/**
* 取得存储在静态变量中的 ApplicationContext.
*/
public static ApplicationContext getApplicationContext() {
checkApplicationContext();
return applicationContext;
}

/**
* 从静态变量 ApplicationContext 中取得 Bean, 自动转型为所赋值对象的类型.
*/
public static <T> T getBean(String name) {
checkApplicationContext();
return (T) applicationContext.getBean(name);
}

/**
* 从静态变量 ApplicationContext 中取得 Bean, 自动转型为所赋值对象的类型.
*/
public static <T> T getBean(Class<T> clazz) {
checkApplicationContext();
return (T) applicationContext.getBean(clazz);
}

/**
* 清除 applicationContext 静态变量.
*/
public static void cleanApplicationContext() {
applicationContext = null;
}

private static void checkApplicationContext() {
if (applicationContext == null) {
throw new IllegalStateException(
"applicaitonContext 未注入,请在 applicationContext.xml 中定义 SpringContextHolder");
}
}
}
```
2020-01-20 15:59:23 +08:00
回复了 monkindey 创建的主题 问与答 回家路上你们都在干什么?
@linbingqinag 剧透一下,有两个结局。
2020-01-19 11:35:05 +08:00
回复了 wadezhao 创建的主题 程序员 问一件羞耻的事情,你们怎么移动光标?
vim 的话不用考虑这些问题。
GUI IDE 配合一下就是 Command + 方向键、ALT + 方向键、Shift + Enter 这些。
2020-01-17 13:53:45 +08:00
回复了 Sniper416 创建的主题 程序员 前端准备入坑 Java ,大佬们有什么要说的?
后端东西太多了:
IOC/DI、数据库、缓存、消息队列、安全、权限、日志、注册发现、熔断、限流、降级、集群、负载均衡、分布式锁、分布式事务、幂等接口、Linux 基础、Docker、K8s……
我毕业设计也做的模式识别,工具不重要,当年还是用的 MATLAB + BPNN 做的,识别率照样 99%。
2020-01-15 10:42:34 +08:00
回复了 NumberFairy 创建的主题 程序员 马上就毕业了才发现自己貌似并不适合做 程序员怎么办?
@Poto 我现在就是那个孙悟空咋办?
2020-01-09 20:23:13 +08:00
回复了 stebest 创建的主题 Blogger 博客是不是需要热一热
@darmau 很漂亮。
2020-01-09 13:45:24 +08:00
回复了 ryougifujino 创建的主题 程序员 有没有博客统一发布系统?
每次提到这个我就想到 IFTTT,奈何国内开放 API 做的不行,
大绿虫车厢 XD
2020-01-08 13:02:13 +08:00
回复了 ysweics 创建的主题 程序员 Macbook Pro 16 纠结配置,求大佬推荐
教育优惠。
2020-01-08 13:00:46 +08:00
回复了 sadfQED2 创建的主题 Python 我突然产生了一个大胆的想法!
用 Go 不就行了。。。
2020-01-03 17:46:50 +08:00
回复了 ffffb 创建的主题 程序员 前端的同学,你们是怎么落地自动化测试的?
我们前端除了会写 ajax 和 css 其他都不会。更别提 nginx、docker、测试、部署了。
把 maven 引入的包删了重新导入一遍看看
把车换成特斯拉
2019-12-30 10:43:34 +08:00
回复了 Cassano 创建的主题 硬件 如何高效利用自己闲置的 PC 和 Mac 呢?
内网击穿
2019-12-27 16:01:51 +08:00
回复了 imn1 创建的主题 电影 有什么电影三部曲内容是各自独立的?
python 2
python 3
python 4
大胆预测
1 ... 11  12  13  14  15  16  17  18  19  20 ... 24  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1100 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 53ms · UTC 23:36 · PVG 07:36 · LAX 16:36 · JFK 19:36
Developed with CodeLauncher
♥ Do have faith in what you're doing.