Question

I've got the following class:

@Service
public class TestService{

    @Autowired
    private Integer size;

    private MyClass myObject;

    public Test(){
        // Default constructor for Spring
    }

    public Test(MyClass myObject){
        this.myObject = myObject;
    }

    // Getters and Setters ...

}

Now I'm instantiating my TestService from outside this class with

new TestService(myObject);

The variable size is of course null. But I want it to be injected from the spring context even though I didn't inject the whole object.

Is it possible to always inject some fields?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top