How to disable Spring autowiring for a certain bean?

前端 未结 4 924
天命终不由人
天命终不由人 2020-12-15 22:39

There are some class in jar (external library), that uses Spring internally. So library class has structure like a:

         


        
4条回答
  •  囚心锁ツ
    2020-12-15 23:07

    This worked for me:

    import org.springframework.beans.factory.FactoryBean;  
    ...  
    @Configuration
    public class TestConfig {
    
        @Bean
        public FactoryBean bean() {
            TestBean bean = Library.createBean();
    
            return new FactoryBean()
            {
                @Override
                public TestBean getObject() throws Exception
                {
                    return bean;
                }
    
                @Override
                public Class getObjectType()
                {
                    return TestBean.class;
                }
    
                @Override
                public boolean isSingleton()
                {
                    return true;
                }
            };
        }
    }
    

提交回复
热议问题