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 ...
随机推荐
- android 观察者模式
1:观察者模式: 1:使用场景:一般使用在自定义控件的事件点击监听上面(或者封装方法进行回调) 2:写观察者模式步骤: (1):声明一个接口 (2):接口里面封装一个抽象方法 (3):需要封装一个 ...
- Git学习笔记(Mac Linux系统)
最近参与学校一个比赛,和队友一起做一个小项目,需要将代码传到Coding(国内git代码托管平台),因此这几天才正式入手git版本控制系统,在这里我就记录一下最近的学习git心得体验,一来分享一下自己 ...
- 从头开始db-oracle
rpm -ivh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpmrpm -ivh http: ...
- Maven最佳实践:Maven仓库(转)
转自:http://juvenshun.iteye.com/blog/359256 什么是Maven仓库 在不用Maven的时候,比如说以前我们用Ant构建项目,在项目目录下,往往会看到一个名为/li ...
- Inventor 2014 sp1/sp2激活
问题: win8.1 inventor2014,不打补丁不兼容: 打了补丁xforce激活始终无法成功. 解决: 1. 使用未打补丁之前的 adlmact.dll 和 adlmact_libFNP.d ...
- Lab_6_SysOps_AutoScaling_Linux_v2.5
System Operations - Lab 6: Using Amazon Elastic Load Balancer (Linux) - 2.5 ======================== ...
- Best Practices for Performance_4.Optimizing Battery Life 获取充电状态、电池信息,"sticky"类型的广播
http://developer.android.com/training/monitoring-device-state/index.htmlhttp://developer.android.com ...
- Oracle 违反协议 OALL8 处于不一致状态
http://blog.sina.com.cn/s/blog_a45aac720100yu3h.html ERROR-util.JDBCExceptionReporter>: 违反协议ERROR ...
- web api 开发记录
1. 修改 api 返回时间格式 //配置返回的时间类型数据格式 GlobalConfiguration.Configuration.Formatters.JsonFormatter.Serializ ...
- Python基础(二)之集合
集合以{}形式表现,一个集合中的元素各不相同,即集合体现为去重的特性.主要用于关系测试,常见的集合操作:交集.并集.插件.子集.父集.对称差集等. 设置集合: list_1 = [1,3,4,5,7, ...