我应该如何使用@Configable在SpringBoot中自动将Bean组装成通用对象 [英] How should I use @Configurable to automatically assemble beans into common objects in springboot
本文介绍了我应该如何使用@Configable在SpringBoot中自动将Bean组装成通用对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
@Configurable
注释,但是当我想使用它的时候,没有完整的文档,很难,需要配置aspectJ
,LTW
,aspectj-maven -plugin
,重启的时候也需要使用-javaagent:/path/to/spring-instrument.jar
,我完全搞不懂了,不知道怎么用,太麻烦了,而且我找不到一个完整的@Configurable
用例,我根本不想用-javaagent:/path/to/spring-instrument.jar
,我找到了很多类似的文章,甚至提到了bytebuddy
。但它们不全面,不能使用,这让我很头疼
- https://blog.csdn.net/crazypandariy/article/details/108172434#comments_15058136
- Spring boot @Configurable
- how to reattach singleton Spring beans upon deserialization
我想这样使用
@Data
@NoArgsConstructor
@Slf4j
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
@JsonSubTypes(
value = {
@JsonSubTypes.Type(value = SinglePipeLink.class),
@JsonSubTypes.Type(value = SequencePipeLink.class),
@JsonSubTypes.Type(value = SplitFlowPipeLink.class),
@JsonSubTypes.Type(LoopPipeLink.class)
})
@Accessors(chain = true)
@Configurable(autowire = Autowire.BY_NAME, preConstruction = true)
public abstract class BasePipeLink implements Serializable {
private static final long serialVersionUID = -5308571029549664750L;
protected String copyFrom;
@Resource @JsonIgnore protected transient RedisService redisService;
}
推荐答案
我最终通过字节伙伴启用了LTW
@EnableSpringConfigured
@EnableAspectJAutoProxy
@EnableLoadTimeWeaving(aspectjWeaving = EnableLoadTimeWeaving.AspectJWeaving.ENABLED)
public class Application {
public static void main(String[] args) {
// Get access to an instrumentation instance
Instrumentation instrumentation = ByteBuddyAgent.install();
// Activate AspectJ weaver
Agent.agentmain("", instrumentation);
// Save instrumentation instance for later use
InstrumentationSavingAgent.agentmain("", instrumentation);
SpringApplication.run(Application.class, args);
}
}
这篇关于我应该如何使用@Configable在SpringBoot中自动将Bean组装成通用对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文