zoukankan      html  css  js  c++  java
  • 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);
    	}
    	
    		
    }
    

      

  • 相关阅读:
    Maven中profile和filtering实现多个环境下的属性过滤
    Java 非法字符: 65279的解决办法
    MySQL军规
    php 时间日期函数
    函数的引入
    linux下修改mysql版本5.7 修改默认字符集
    mysql语句规范
    永久修改mysql提示符
    复杂函数
    函数的特性
  • 原文地址:https://www.cnblogs.com/rench/p/3555443.html
Copyright © 2011-2022 走看看