I'm new to JEE and have an issue with CDI that I can not figure out by myself.
I have a simple converter class in which I try to inject an object which have to provide the conversion logic, but injection seems not to work for this case. The converter class looks like this:
@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);
}
}
When the @Converter is triggered it throws an NullPointerException
because the property crypto
is not being initialized from the container. Why is that?
I'm using Glassfish 4 and in all other cases @Injection works just fine.
Is it not possible to use CDI on converters?
Any help will be appreciated :)
Aucun commentaire:
Enregistrer un commentaire