guyeuro
V2EX  ›  问与答

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

  •  
  •   guyeuro · Aug 23, 2017 · 1910 views
    This topic created in 3226 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   ·   3209 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 12:29 · PVG 20:29 · LAX 05:29 · JFK 08:29
    ♥ Do have faith in what you're doing.