0

Ihave property class:

@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "my-api")
public class MyApiProperties {

    ...

    private MyClient myClient; 

    @Getter
    @Setter
    public static class MyClient {
        private String host;
        private long connectionTimeout;
        private long receiveTimeout;
    }
}

I can config it:

my-api:
  my-client:
    host: http://1...
    connection-timeout: 30000
    receive-timeout: 60000

And I can Inject it:

@Value("${my-api.my-client.host}")
private String host;

But can I inject full object like this?

@Value("${my-api.my-client}")
private MyClient myClient;
ip696
  • 6,574
  • 12
  • 65
  • 128
  • Possible duplicate of [Spring @Value property for custom class](https://stackoverflow.com/questions/26063171/spring-value-property-for-custom-class) – vahdet Mar 15 '19 at 09:35
  • No. It isn't a component and `@Value` doesn't work like that. You can inject the enclosing `MyApiProperties` as you should as the properties are part of that object. – M. Deinum Mar 15 '19 at 09:41

0 Answers0