I have a class having Autowired Constructor.
now when i am autowiring this class object in my class. how do i pass arguments for constructor??
example code: Class having Autowired Constructor:
@Component
public class Transformer {
private String dataSource;
@Autowired
public Transformer(String dataSource)
{
this.dataSource = dataSource;
}
}
Class using autowire for component having constructor with arguments:
@Component
public class TransformerUser {
private String dataSource;
@Autowired
public TransformerUser(String dataSource)
{
this.dataSource = dataSource;
}
@Autowired
Transformer transformer;
}
this code fails with message
"Unsatisfied dependency expressed through constructor parameter 0"
while creating bean of type Transformer.
how do i pass the arguments to Transformer while Autorwiring it??
Then create a config file
you can use resource files
1) define a file like database.properties and put a variable like
in this file
2) define a configuration class
also you can use placeholder that is much better of using constructor in this case