Can we add @Autowired
on primitive setter method of a bean?
How does @Autowired
work for primitive?
Can we add @Autowired
on primitive setter method of a bean?
How does @Autowired
work for primitive?
No, for primitive value use @Value
annotation. @Autowired
is looking for bean.
Read How can I inject a property value into a Spring Bean which was configured using annotations?
With Spring Boot this is even easier:
@Component
@ConfigurationProperties(prefix="connection")
public class ConnectionSettings {
private String username;
private InetAddress remoteAddress;
// ... getters and setters
}
where values are configured in application.yml
connection:
username: admin
remoteAddress: 192.168.1.1