guyeuro
V2EX  ›  问与答

@Autowired @Resource 之类的注解和初始化块哪个先执行?

  •  
  •   guyeuro · Aug 23, 2017 · 1946 views
    This topic created in 3244 days ago, the information mentioned may be changed or developed.

    如下代码,出错了

    public class MyController{
      @Autowired
      private RedisTemplate<String, String> redisTemplate;
    
      SetOperations<String, String> setOperations;
      HashOperations<String, String, String> hashOperations;
    
      {
        setOperations = redisTemplate.opsForSet();
        hashOperations = redisTemplate.opsForHash();
      }
    

    是不是注解没有初始化块先执行? 这种状况如何改?

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   880 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 20:54 · PVG 04:54 · LAX 13:54 · JFK 16:54
    ♥ Do have faith in what you're doing.