我有一个简单的AttributeConverter实现,我尝试注入一个必须提供转换逻辑的对象,但@Inject似乎不适用于这种情况.转换器类看起来像这样:
@Converter(autoApply=false)
public class String2ByteArrayConverter implements AttributeConverter<String, byte[]>
{
@Inject
private Crypto crypto;
@Override
public byte[] convertToDatabaseColumn(String usrReadable)
{
return crypto.pg_encrypt(usrReadable);
}
@Override
public String convertToEntityAttribute(byte[] dbType)
{
return crypto.pg_decrypt(dbType);
}
}
Run Code Online (Sandbox Code Playgroud)
当@Converter触发它时会抛出一个NullPointerException因为该属性crypto没有从容器初始化.这是为什么?
我正在使用Glassfish 4,在所有其他情况下@Inject工作得很好.
是否无法在转换器上使用CDI?
任何帮助将不胜感激 :)
我的问题的重点是AttributeConverter部分.我知道,要使CDI工作,bean必须满足http://docs.oracle.com/javaee/6/tutorial/doc/gjfzi.html所述的条件.我也尝试通过实现以下构造函数来强制CDI工作:
@Inject
public String2ByteArrayConverter(Crypto crypto)
{
this.crypto = crypto;
}
Run Code Online (Sandbox Code Playgroud)
现在我得到以下异常,但没有给我任何线索:
2015-07-23T01:03:24.835+0200|Severe: Exception during life cycle processing
org.glassfish.deployment.common.DeploymentException: Exception [EclipseLink-28019] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: …Run Code Online (Sandbox Code Playgroud) 几天来,我一直在尝试为基于证书的客户端身份验证设置开发环境,但这只是不起作用。我正在使用Glassfish 4文档(安全性指南),并根据它创建用于测试目的的自签名客户端证书,但由于无法完整描述整个过程,因此我不确定所缺少的内容。当我为Http-Listener启用客户端身份验证并且在服务器日志中没有收到任何错误消息时,但是当我尝试从浏览器进行连接时,我无法与服务器建立连接。没有此选项,我的Web应用程序将正常运行。在Chrome浏览器中,我看到以下消息:
无法访问该网站
127.0.0.1拒绝连接。
ERR_CONNECTION_REFUSED
在Firefox中:
页面加载时,与192.168.1.9:8181的连接被中断。
因此对我来说似乎正在发生某些事情(不幸的是,我无法确切理解是什么),但是无法建立连接。
由于设置非常复杂,因此我正在寻找具有逐步说明的教程或操作方法页面,但是对您的帮助和建议将不胜感激。
authentication client-certificates ssl-certificate glassfish-4.1