w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Reference a bean as part of a constructor to a different bean in java config
public User user() {
    return new User("first", "second", "third");

public Department department() {
    return new Department("fourth", "fifth", user());

Now you can user @Autowired in other classes that are in the container and inject your user or department (e.g. in a controller)

private User user; // will return the user from the user() java config
defined bean

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.