1
@Component
public class Module {
    public Module(String type, List<String> data) {
        .
        .
        .
    }
}

How do I initialize User, while passing the constructor's parameters, where Module is Autowired into another class: where the parameter values here are dynamic, whereby, for example, they are fetched via a user submission form, thereby can't be stored in a file.

@Component
public class AnotherClass {
    @Autowired
    Module module(....)????? // How do I do it here
    .
    .
    .
}

In this case, type parameter in Constructor it will be fixed and known in the startup. But data is a dynamic parameter.

Santosh
  • 1,849
  • 4
  • 19
  • 31
  • Do you know the user details at application startup? If not, then creating a User instance as a bean is not a viable option. – NicoE Dec 02 '15 at 15:29
  • 1
    Possible duplicate of [Anyway to @Autowire a bean that requires constructor arguments?](http://stackoverflow.com/questions/6739566/anyway-to-autowire-a-bean-that-requires-constructor-arguments) – Robert Moskal Dec 02 '15 at 15:33
  • @NicoE: I have modified the question. You were right if we take User model. Now, in the above case, one argument is fixed and other one dynamically we need to pass while using it. – Santosh Dec 02 '15 at 15:38
  • To be more clear, how do I pass dynamic values while saying @Autowire for constructor values? – Santosh Dec 02 '15 at 15:44
  • See the above. The short answer is you don't unless they can be simple values from the property configurer. – Robert Moskal Dec 02 '15 at 16:00

0 Answers0