代码之家  ›  专栏  ›  技术社区  ›  Jonathan S. Fisher

EclipseLink:如何在没有JEE/CDI的情况下启用Bean验证?(在SE中称为启用)

  •  0
  • Jonathan S. Fisher  · 技术社区  · 8 年前

    我们有一个测试扩展,为我们的测试创建一个EntityManager:

    Map<String, String> properties = new HashMap<String, String>(); properties.put(PersistenceUnitProperties.JDBC_DRIVER, DRIVER_NAME); properties.put(PersistenceUnitProperties.JDBC_URL, createUrl(testInstance)); properties.put(PersistenceUnitProperties.JDBC_USER, DB_USER); properties.put(PersistenceUnitProperties.COORDINATION_PROTOCOL, null); emf = Persistence.createEntityManagerFactory(PU_NAME, properties); ... EntityManager em = emf.createEntityManager();

    不过,我们注意到,在预持久化或预更新时,没有启动BeanValidator,尽管我们的其他验证程序启动得很好。这是有道理的,在JEE容器中,Bean验证库由容器本身提供。

    如果我们把EclipseLink调用到OpenWebBeans这样的东西上并将其包含在测试类路径中,有可能吗?

    1 回复  |  直到 8 年前
        1
  •  0
  •   Jonathan S. Fisher    8 年前

    这很简单,只需将其添加到我们的pom中:

        <dependency>
            <groupId>org.apache.bval</groupId>
            <artifactId>bval-jsr</artifactId>
            <version>1.1.2</version>
            <scope>test</scope>
        </dependency>
    
    推荐文章