Javax @NotNull annotation usage

后端 未结 4 451
隐瞒了意图╮
隐瞒了意图╮ 2021-01-17 12:49

I have a simple method to get a list of documents for a given companyId. Here is the method:

@Override
public List getDocumentL         


        
4条回答
  •  独厮守ぢ
    2021-01-17 13:18

    If you @Inject a class with your method, its working as expected.

    @Stateless
    public class MyBean{ 
        @Inject
        TestClass test;
    }
    

    and

    public class TestClass {
        public List getDocumentList(@NotNull Integer companyId)
        {
            //...
        }
    }
    

    ConstraintViolationException when you call your method with null parameter:

    WFLYEJB0034: EJB Invocation failed on component MyBean for method ...:
    javax.ejb.EJBException: javax.validation.ConstraintViolationException:
    1 constraint violation(s) occurred during method validation.
    

提交回复
热议问题