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 ...
随机推荐
- 数据库备份Sql
今天学习心得: 数据库备份语句: backup database ZhiHuiGongDi To disk = 'D:\zhihuigongdi20150824.bak'
- 手机网页调试利器: Chrome
新开发的网页需要在手机或是模拟机上运行测试, 可以借助 Chrome提供的手机网页预览程序进行简单调试.查看 制作的网页是否能够适合各种手机型号使用. 下面所以下如何使用Chrome调试多类型手机网页 ...
- [zz] ROC曲线
wiki https://zh.wikipedia.org/wiki/ROC%E6%9B%B2%E7%BA%BF 在信号检测理论中,接收者操作特征曲线(receiver operating chara ...
- LeetCode "Largest Divisible Subset" !
Very nice DP problem. The key fact of a mutual-divisible subset: if a new number n, is divisible wit ...
- Using dojo/query(翻译)
In this tutorial, we will learn about DOM querying and how the dojo/query module allows you to easil ...
- canvas ---个性时钟
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- System.Data.EntityState”在未被引用的程序集中定义
类型“System.Data.EntityState”在未被引用的程序集中定义.必须添加对程序集“System.Data.Entity, Version=4.0.0.0, Culture=neu 错误 ...
- MVC4中 访问webservice 出现无法找到资源的错误
出现这个情况,是mvc将webservice.asmx解析成了控制器,下面先将这个控制器忽略 继续访问出现这样的错误: 下面修改配置文件 访问成功
- JS移动端如何监听软键盘回车事件
移动端经常项目中会有搜索之类的功能,一般实现的是按搜索按钮进行搜索,如果要像PC端一样实现按回车键进行搜索该怎么实现呢? 方法很简单,就是在搜索框的input外面套一个form标签 注意点:form ...
- store操作
store.remove(rs); store.sync({ success: function (e, opt) { this.store.commitChanges(); }, failure: ...