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 注入静态变量的更多相关文章

  1. Spring注入静态变量的方法,以及CXF如何获取客户端IP

    1.如果使用@Resource注解来注入静态变量的,服务器启动就会报错的.可以新增一个set方法,同时在set方法上用@Resource注解来注入. 2.或者直接在Spring的配置文件中使用< ...

  2. [转]spring 注入静态变量

    原文: http://www.cnblogs.com/xing901022/p/4168124.html 今天碰到一个问题,我的一个工具类提供了几种静态方法,静态方法需要另外一个类的实例提供处理,因此 ...

  3. 【Spring开发】—— Spring注入静态变量

    今天碰到一个问题,我的一个类提供了几种静态方法,静态方法需要另外一个类的实例提供处理,因此就写出了这样的代码: Class aa{ private static XXX xxx; xxx = Bean ...

  4. Spring注入静态变量(转)

    今天碰到一个问题,我的一个工具类提供了几种静态方法,静态方法需要另外一个类的实例提供处理,因此就写出了这样的代码: Class Util{ private static XXX xxx; xxx = ...

  5. spring boot 静态变量注入配置文件

    spring 静态变量注入 spring 中不支持直接进行静态变量值的注入,我们看一下代码: @Component(value = "KafkaConfig") @Configur ...

  6. SpringBoot使用@Value从yml文件取值为空--注入静态变量

    SpringBoot使用@Value从yml文件取值为空--注入静态变量     1.application.yml中配置内容如下:   pcacmgr:   publicCertFilePath: ...

  7. spring不能注入静态变量的原因

    静态方法是属于类(class)的,普通方法才是属于实体对象(也就是New出来的对象)的,spring注入是在容器中实例化对象,所以不能使用静态方法. @Autowired private static ...

  8. 解决Spring对静态变量无法注入问题(转)

    问题今天在学习的过程中想写一个连接和线程绑定的JDBCUtils工具类,但测试时发现一直报空指针异常,上网查了之后Spring并不支持对静态成员变量注入,所以光试用@Autowired肯定是不行的.可 ...

  9. spring 给静态变量注入值

    一般在spring中,给static变量加上@Autowired注解的时候会报空指针异常错误. 解决: 1.通过xml配置文件配置 这个就不多说了. 2.通过注解 @Component public ...

随机推荐

  1. LeetCode---Binary Search

    475. Heaters 思路:每趟循环查找离房子最近的热水器,计算距离,最后取最大距离 public int findRadius(int[] houses, int[] heaters) { Ar ...

  2. div标签上下滚动

    <div id="myInfo" style={{width:'100%',height:'100%', overflow:'scroll'}}></div> ...

  3. MSER算法介绍

    MSER代码编译: matlabroot %如果是VS2010则解压VS2010MEX支持文件到MATLAB根目录 unzip('E:\Software\develop Tools\VS2010MEX ...

  4. python之 Redis

    Redis redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorte ...

  5. Mac iTerm with Powerline

    1. 下载iTerm 地址: http://www.iterm2.com/ 完全可以取代Mac自带的终端了. 2. 之前我装过oh-my-zsh git clone git://github.com/ ...

  6. SQL数据库添加新账号,只操作指定数据库

    思路: 1.创建数据库服务器登录用户 2.创建指定数据库的用户,并且和服务器用户联系起来 3.给数据库的用户添加角色 代码实现: 1.创建名为login的服务器登录用户dba,尼玛dbpwd,默认数据 ...

  7. Linux命令(23)grep命令的使用

    grep(global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正 ...

  8. C++中三种new的用法

    转载自:http://news.ccidnet.com/art/32855/20100713/2114025_1.html 作者: mt 1 new operator,也叫new表达式:new表达式比 ...

  9. 一键配置openvpn

    页面:https://github.com/Nyr/openvpn-install openvpn-install OpenVPN road warrior installer for Debian, ...

  10. [DFNews] Fire-Eye与Fox IT联合推出Cryptolocker解锁网站

    Cryptolocker是臭名昭著的勒索程序,使用AES加密后密钥回传,用户除了缴纳赎金之外基本无法解密数据. 近日,知名安全公司Fire-Eye与Fox IT联合推出了针对该勒索程序的解锁网站 ht ...