How to inject a service into my own class

Hi,
I create a my own class and try to inject a service into the class. But this service can’t be initialized automatically. It shows an “NullPointerException” error when I call a method in this service. This service works well when it’s injected in editor class which is generated by CUBA-PLATFORM.

public class IPManager {

    @Inject
    private GetTestdefbyTestspecService testSpecService;

    @Inject
    private Metadata metadata;


    public ArrayList<IPDETAIL> CreateIPDetailByItem(IPHEADER ipHeader, String ItemNum, Date beginDate, Date endDate)
    {
        ArrayList<TESTSPEC> testspecArrayList = 
        testSpecService.GetTestdefbyTestspec(ItemNum,beginDate,endDate);   //NullPointerException here.
   }

Hey,
It is hard to say cos there is no way to tell in what module your class is.
But there is a universal solution: try to use AppBeans#get to get an instance of your bean

I put @component annotation to my own class and inject it. It works.

@Component("IPManager")
public class IPManager {
}