对 RAR 模块中的 Bean 验证进行故障诊断
未能通过验证的 RAR Bean 将不会投入使用。发生约束违例时,应用程序遇到资源连接问题,这些问题随 Bean 类型以及 RAR 的部署方式不同而异。本主题说明如何了解、处理和防止这些已知问题。
RAR Bean 约束违例
在验证违反了一个或多个约束的 RAR Bean 实例时,WebSphere® Application Server 显示约束违例异常并在系统日志中报告所有约束违例。必须确定并解析所有约束违例的原因才能恢复与受影响资源的完全连接。
问题确定从参阅 RAR 提供程序文档以获取违例中指示的配置属性的有效值开始。如果属性值无效,那么您必须根据文档进行重新配置,然后重新启动资源适配器。如果适配器嵌入在应用程序中,请重新启动该应用程序以重新启动适配器;如果适配器是独立的,请重新启动应用程序服务器。
如果违例中指示的配置属性值有效,那么可能是对 Bean 不正确地指定了约束,或者 Bean 正在不正确地计算属性值。在这些情况下,RAR 供应商必须解决该问题。
如果问题是由于约束定义(实现)不正确所致,那么 Bean 验证提供者必须解决该问题。在这些情况下,如果 RAR 由 IBM® 提供,或者 RAR 使用应用程序服务器所提供的 Bean 验证实现,请与 IBM 技术支持联系以继续问题确定。
ResourceAdapter Bean
当服务器启动 Java™ 2 连接器 (J2C) 资源适配器时,将会验证 ResourceAdapter Bean。如果未能通过验证,那么服务器将拒绝 ResourceAdapter 实例,并且生成的约束违例异常将导致 J2C 资源适配器失败。应用程序无法建立与资源的出站连接,并且资源无法将消息传送至应用程序。对于嵌入式适配器,适配器所嵌入在的应用程序无法启动。涉及资源的不确定事务无法恢复。
[9/29/10 10:51:24:125 CDT] 00000000 BeanValidatio E
J2CA0238E: JavaBean com.my.company.adapter.MyConnector@7efa7efa failed Bean Validation due to one or more invalid
configuration settings indicated in the following list of constraint violations:
ConstraintViolationImpl{interpolatedMessage='The minimum size is 2', propertyPath=dataBaseName, rootBeanClass=class
com.my.company.adapter.MyConnector, messageTemplate='The minimum size is 2'}
ConstraintViolationImpl{interpolatedMessage='must be greater than or equal to 10', propertyPath=idleTimeout, rootBeanClass=class
com.my.company.adapter.MyConnector, messageTemplate='{javax.validation.constraints.Min.message}'}
…
[9/29/10 10:51:24:468 CDT] 00000000 RALifeCycleMa E
J2CA0128E: An Exception occurred while trying to start ResourceAdapter
cells/IBM-46DF84D297BNode01Cell/nodes/IBM-46DF84D297BNode01/resources.xml#J2CResourceAdapter_1285109360562. The exception is:
com.ibm.ejs.j2c.metadata.ConstraintViolationException
at com.ibm.ejs.j2c.metadata.BeanValidationHelper.validate(
at com.ibm.ejs.j2c.RAWrapperImpl.createAndConfigureRA(
at com.ibm.ejs.j2c.RAWrapperImpl.startRA(
at com.ibm.ejs.j2c.RALifeCycleManagerImpl.startRA(
at com.ibm.ejs.j2c.RALifeCycleManagerImpl.resourceProviderEvent(
. . .
ManagedConnectionFactory Bean
在对 J2C 连接工厂执行初始 Java 命名和目录接口 (JNDI) 查找期间,将会验证 ManagedConnectionFactory JavaBeans。
如果未能通过验证,那么应用程序服务器将拒绝 ManagedConnectionFactory 实例并向执行该查找的应用程序显示命名异常。此异常指示因果约束违例异常 (javax.validation.ConstraintValidationException)。
应用程序无法建立与资源的出站连接。通过连接工厂所创建的资源连接启动的不确定事务无法恢复。
[9/30/10 7:58:58:734 CDT] 00000023 BeanValidatio E
J2CA0238E: JavaBean com.my.company.adapter.MyMcf@7dd07dd0 failed Bean Validation due to one or more invalid
configuration settings indicated in the following list of constraint violations:
ConstraintViolationImpl{interpolatedMessage='must be less than or equal to 30', propertyPath=mcfProperty2,
rootBeanClass=class com.my.company.adapter.MyMcf, messageTemplate='{javax.validation.constraints.Max.message}'}
ConstraintViolationImpl{interpolatedMessage='The value should be greater than 10', propertyPath=mcfProperty4,
rootBeanClass=class com.my.company.adapter.MyMcf, messageTemplate='The value should be greater than 10'}
….
[9/30/10 7:58:58:765 CDT] 00000023 ConnectionFac E
J2CA0009E: An exception occurred while trying to instantiate the ManagedConnectionFactory class com.my.company.adapter.MyMcf
used by resource j2c/MyConnector : com.ibm.ejs.j2c.metadata.ConstraintViolationException
at com.ibm.ejs.j2c.metadata.BeanValidationHelper.validate(
at com.ibm.ejs.j2c.ServerFunction.validate(
at com.ibm.ejs.j2c.J2CUtilityClass.createMCFEntry(
…
at javax.naming.InitialContext.lookup(
at com.my.company.app.MyEjbImpl.testJbv(
. . .
ActivationSpec Bean 违例
在应用程序启动时,将会验证 ActivationSpec Bean。这是在应用程序服务器最初激活与 J2C 激活规范绑定的消息端点时。这些激活规范在其配置中对 Bean 类进行命名。如果未能通过验证,那么该端点将无法激活,并且生成的约束违例异常将导致托管该端点的应用程序失败。
由于包含激活规范的 J2C 资源适配器已启动,应用程序仍可以建立与资源的连接。资源可以将消息传送至已成功激活的端点。如果激活规范是在嵌入式资源适配器内定义的,那么服务器将在停止应用程序的过程中停止该适配器。由包含激活规范的先前资源适配器实例所传送的失败事务性消息将无法恢复。
[9/29/10 10:52:05:125 CDT] 00000009 BeanValidatio E
J2CA0238E: JavaBean com.my.company.adapter.MyActSpec@51625162 failed Bean Validation due to one or more invalid
configuration settings indicated in the following list of constraint violations:
ConstraintViolationImpl{interpolatedMessage='Size should be between 2 and 4', propertyPath=asProperty1,
rootBeanClass=class com.my.company.adapter.MyActSpec, messageTemplate='Size should be between 2 and 4'}
ConstraintViolationImpl{interpolatedMessage='Should be < 30', propertyPath=asProperty2,
rootBeanClass=class com.my.company.adapter.MyActSpec, messageTemplate='Should be < 30'}
[9/29/10 10:52:05:171 CDT] 00000009 RAWrapperImpl E
J2CA0089E: The method activateEndpoint on ResourceAdapter JavaBean
cells/IBM-46DF84D297BNode01Cell/nodes/IBM-46DF84D297BNode01/resources.xml#J2CResourceAdapter_1285109389828
failed with the following exception:
javax.resource.ResourceException: com.ibm.ejs.j2c.metadata.ConstraintViolationException
at com.ibm.ejs.j2c.ActivationSpecWrapperImpl.validateActivation…( at com.ibm.ejs.j2c.ActivationSpecWrapperImpl.createAndInitializ…(
at com.ibm.ejs.j2c.ActivationSpecWrapperImpl.activateEndpoint(
…
[9/29/10 10:52:05:750 CDT] 00000009 ApplicationMg A WSVR0217I: Stopping application: my_company_app
. . .
AdministeredObject Bean
当服务器启动其配置中包含受管对象的 J2C 资源适配器时,将会验证 AdministeredObject Bean。如果未能通过验证,那么服务器将拒绝 AdministeredObject 实例,并且生成的约束违例异常将导致资源适配器失败。
[9/29/10 10:51:25:125 CDT] 00000000 BeanValidatio E
J2CA0238E: JavaBean com.my.company.adapter.MyAdminObj@3a803a80 failed Bean Validation due to one or more invalid
configuration settings indicated in the following list of constraint violations:
ConstraintViolationImpl{interpolatedMessage='The value should be greater than 10', propertyPath=aoProperty4,
rootBeanClass=class com.my.company.adapter.MyAdminObj, messageTemplate='The value should be greater than 10'}
…
[9/29/10 10:51:25:218 CDT] 00000000 AdminObjectSe A
J2CA0017I: An exception occurred while building the serializable for JNDI deployment of jms/MyAdminObj :
com.ibm.ejs.j2c.metadata.ConstraintViolationException
at com.ibm.ejs.j2c.metadata.BeanValidationHelper.validate(
at com.ibm.ejs.j2c.metadata.BeanValidationHelper.validate(
at com.ibm.ejs.j2c.AdminObjectSerBuilderImpl._createAndValidate…(
at com.ibm.ejs.j2c.AdminObjectSerBuilderImpl.createAndValidate…(
at com.ibm.ejs.j2c.RALifeCycleManagerImpl.startRA(
. . .