001package io.avaje.inject; 002 003import java.lang.annotation.ElementType; 004import java.lang.annotation.Retention; 005import java.lang.annotation.RetentionPolicy; 006import java.lang.annotation.Target; 007 008/** 009 * Marks methods on a <code>@Factory</code> bean that create dependencies. 010 * <p> 011 * See {@link Factory}. 012 * </p> 013 * 014 * <pre>{@code 015 * 016 * @Factory 017 * class Configuration { 018 * 019 * private final StartConfig startConfig; 020 * 021 * @Inject 022 * Configuration(StartConfig startConfig) { 023 * this.startConfig = startConfig; 024 * } 025 * 026 * @Bean 027 * Foo buildFoo() { 028 * ... 029 * return new Foo(...); 030 * } 031 * 032 * @Bean 033 * Bar buildBar(Foo foo, Bazz bazz) { 034 * ... 035 * return new Bar(...); 036 * } 037 * } 038 * }</pre> 039 */ 040@Target(ElementType.METHOD) 041@Retention(RetentionPolicy.RUNTIME) 042public @interface Bean { 043 044 /** 045 * Specify a method to be treated like a <code>@PostConstruct</code> 046 */ 047 String initMethod() default ""; 048 049 /** 050 * Specify a method to be treated like a <code>@PreDestroy</code> 051 */ 052 String destroyMethod() default ""; 053 054 /** 055 * Specify the priority of the destroy method to control its execution 056 * order relative to other destroy methods. 057 * <p> 058 * Low values execute earlier than high values. All destroy methods without 059 * any explicit priority are given a value of 1000. 060 */ 061 int destroyPriority() default 0; 062 063 /** 064 * Specify that the concrete instance of the bean is an AutoCloseable. Use if your bean interface 065 * doesn't extend AutoCloseable but the concrete class implements it. 066 */ 067 boolean autoCloseable() default false; 068}