guyeuro
V2EX  ›  问与答

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

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