spring 注入静态变量
import java.util.Iterator;
import java.util.LinkedList; import javax.annotation.PostConstruct;
import javax.annotation.Resource; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"../../../../../spring.xml"})
public class AutoDown{ @Autowired
private JdbcTemplate jdbcTemplate;
private static AutoDown autoDown;
@PostConstruct
public void init(){
System.out.println("1111");
autoDown = this;
autoDown.jdbcTemplate = this.jdbcTemplate;
System.out.println("init");
}
@Test
public void testStatic(){
System.out.println("11111111");
System.out.println(autoDown.jdbcTemplate);
int i = autoDown.jdbcTemplate.queryForObject("select count(1) from siminfo", Integer.class);
System.out.println(i);
} }
spring 注入静态变量的更多相关文章
- Spring注入静态变量的方法,以及CXF如何获取客户端IP
1.如果使用@Resource注解来注入静态变量的,服务器启动就会报错的.可以新增一个set方法,同时在set方法上用@Resource注解来注入. 2.或者直接在Spring的配置文件中使用< ...
- [转]spring 注入静态变量
原文: http://www.cnblogs.com/xing901022/p/4168124.html 今天碰到一个问题,我的一个工具类提供了几种静态方法,静态方法需要另外一个类的实例提供处理,因此 ...
- 【Spring开发】—— Spring注入静态变量
今天碰到一个问题,我的一个类提供了几种静态方法,静态方法需要另外一个类的实例提供处理,因此就写出了这样的代码: Class aa{ private static XXX xxx; xxx = Bean ...
- Spring注入静态变量(转)
今天碰到一个问题,我的一个工具类提供了几种静态方法,静态方法需要另外一个类的实例提供处理,因此就写出了这样的代码: Class Util{ private static XXX xxx; xxx = ...
- spring boot 静态变量注入配置文件
spring 静态变量注入 spring 中不支持直接进行静态变量值的注入,我们看一下代码: @Component(value = "KafkaConfig") @Configur ...
- SpringBoot使用@Value从yml文件取值为空--注入静态变量
SpringBoot使用@Value从yml文件取值为空--注入静态变量 1.application.yml中配置内容如下: pcacmgr: publicCertFilePath: ...
- spring不能注入静态变量的原因
静态方法是属于类(class)的,普通方法才是属于实体对象(也就是New出来的对象)的,spring注入是在容器中实例化对象,所以不能使用静态方法. @Autowired private static ...
- 解决Spring对静态变量无法注入问题(转)
问题今天在学习的过程中想写一个连接和线程绑定的JDBCUtils工具类,但测试时发现一直报空指针异常,上网查了之后Spring并不支持对静态成员变量注入,所以光试用@Autowired肯定是不行的.可 ...
- spring 给静态变量注入值
一般在spring中,给static变量加上@Autowired注解的时候会报空指针异常错误. 解决: 1.通过xml配置文件配置 这个就不多说了. 2.通过注解 @Component public ...
随机推荐
- Linux测试环境部署tomcat(二)
安装配置tomcat 1:在http://tomcat.apache.org/download-80.cgi下载最新安装包 2:安装tomcat 将apache-tomcat-8.0.21.tar.g ...
- html框架
1.框架的概念 框架:将一个浏览器窗口划分成若干个小窗口 2.框架集合框架页 框架集<frameset>:主要用来划分窗口的. 框架页<frame>:主要用来指定窗口默认显示的 ...
- VS高效开发快捷键
Ctrl + Tab 标签切换 Ctrl + '-'向后导航 Ctrl + Shift+'-'向前导航 Ctrl +Shift +空格 提示函数参数 Ctrl +F4 退出本标签 Ctrl+F 查找 ...
- 基站查询接口,基站查询API
查询接口为商用,用于软件开发,非开发用户用不上.(说明:接口不能进行手机定位) 如需申请key,请联系QQ 2258172309. 1.移动联通基站查询接口 请求示例:http://www.cellm ...
- symfony2取得web目录绝对路径、相对路径、网址的函数是什么
对于你的需求,Symfony2通过DIC提供了kernel服务,以及request(请求)的封装. 在controller里(在其他地方你可以自行注入kernel,这个服务是HttpKernel库里的 ...
- scala环境配置
scala下载 解压 vim ~/.profile export PATH=~/dev/scala/scala-/bin:$PATH idea的scala插件这个由于太大,只能手工下载,注意下载的版本 ...
- 各公司年资金归集汇总sql
select bd_accid.accidcode, bd_accid.accidname, -- fts_voucher_b.interestdate, -- fts_voucher_b.summa ...
- 【转载】Keil中的USE MicroLib说明
在keil建立ARM的工程时 其中有一项是选 use MicroLIB 由于对KEIL不是很熟悉,于是就查了查,得到了以下信息: microlib 是缺省 C 库的备选库. 它旨在与需要装入到极少量内 ...
- Java多线程系列- DelayQueue延时队列
我们在开发中,有如下场景 a) 关闭空闲连接.服务器中,有很多客户端的连接,空闲一段时间之后需要关闭之.b) 缓存.缓存中的对象,超过了空闲时间,需要从缓存中移出.c) 任务超时处理.在网络协议滑动窗 ...
- 流水灯 外侧<->中间<->外侧
/* //side<-center->side //side->center<-side //loop *// #include "reg52.h" voi ...