20 Ocak 2022 Perşembe

Jakarta EE @Produces Anotasyonu - Bean Tanımlar

Giriş
Açıklaması şöyle
Even though the @Produces annotation is used for defining injectable beans, methods with this annotation also benefit from dependency injection
Örnek
Şöyle yaparız
@Produces
MyBean mb(InjectMe injectMe) { 
  // "injectMe" is injected and can be used for constructing "MyBean"
  return new MyBean(injectMe);
}
Örnek
Şöyle yaparız
public interface Connection extends AutoCloseable {

  void commit(String execute);
}

@ApplicationScoped
class ConnectionProducer {


  @Produces
  Connection getConnection() {
    return new SimpleConnection();
  }

  public void dispose(@Disposes Connection connection) throws Exception {
    connection.close();
  }
}

Hiç yorum yok:

Yorum Gönder

Bean Validation @GroupSequence Anotasyonu

Örnek Elimizde şöyle bir kod olsun public class SampleRequest {   @NotNull   LocalDate startDate;   @NotNull   LocalDate endDate;   @AssertT...