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. IPv6实验准备

    这篇是我的第一篇博客,我想先对H3C的<IPv6技术>的实验部分进行实验和总结,欢迎评论转载. 本实验用的网路设备模拟器是HCL_7.1.59,hcl的这款模拟器非常耗费内存,各种报错,因 ...

  2. etcd第一集

    网站:https://github.com/coreos/etcd 一些观点:https://yq.aliyun.com/articles/11035 1.etcd是键值存储仓库,配置共享和服务发现2 ...

  3. c# equals与==

    对于值类型,如果对象的值相等,则相等运算符 (==) 返回 true,否则返回 false.对于string 以外的引用类型,如果两个对象引用同一个对象,则 == 返回 true.对于 string ...

  4. XML组成结构以及C#通过DTD验证规范性

    XML 文档包含元素和属性等,它们提供一种灵活且功能强大的方法,为应用程序和组织之间交换数据.所有的 XML 文档(以及 HTML 文档)均由以下简单的构建模块构成: 1.元素 元素是XML的主要构建 ...

  5. Oracle常用的性能诊断语句

    --1.阻塞及等待事件信息查询 -- 查询所有会话的状态.等待类型及当前正在执行的SQL脚本 select se.SID, se.SERIAL#, se.Status, se.Event, se.BL ...

  6. Who is using Asio?

    https://think-async.com/Asio/WhoIsUsingAsio

  7. 在macos上利用vmware fusion安装Ubuntu

    1. 安装vmware fusion http://www.vmware.com/products/fusion 下载以后,可以在网上找注册码,最好下载最新的,这里下载的是7的版本 2. 下载ubun ...

  8. Node.js的循环与异步问题

    (转自:http://bbs.tianya.cn/post-itinfo-280080-1.shtml) Node.js 的异步机制由事件和回调函数实现,一开始接触可能会感觉违反常规,但习惯 以后就会 ...

  9. 关于Maven项目

    用maven 工程搭建项目,在搭建好之后,运行时却抛出了这样的错误:  Error configuring application listener of class org.springframew ...

  10. iscsi 怎么搞

    I recently reinstalled the software on my NAS (open media vault) and tidied up the host name etc. As ...