Jasypt与Hibernate 4和Spring 3.1集成

我在我的应用程序中使用Spring 3.1 Hibernate 4.1.我想使用Jasypt将某些字段(例如密码)以加密形式存储.但是在集成中,我面临以下异常:

java.lang.AbstractMethodError: org.jasypt.hibernate.type.EncryptedStringType.nullSafeSet(Ljava/sql/PreparedStatement;Ljava/lang/Object;ILorg/hibernate/engine/spi/SessionImplementor;)V

为了将Spring hibernate与Jasypt集成在一起,我遵循以下步骤:

>在lib文件夹中添加了jasypt-1.8.jar.
>在dispatcher-servlet(配置文件)中添加了以下内容

< bean id =“ hibernateStringEncryptor”
        class =“ org.jasypt.hibernate.encryptor.HibernatePBEStringEncryptor”
        lazy-init =“ false”>
        
            hibernateStringEncryptor
        
        
            茉莉花
        
    < / bean>
>在实体上放置以下代码:

@TypeDef(
                name =“ encryptedString”,
                typeClass = EncryptedStringType.class,
                参数= {
                        @Parameter(name =“ encryptorRegisteredName”,value =“ hibernateStringEncryptor”)
                        }
                )

但是它没有得到预期的结果.请帮助我解决此异常.

问候,

阿伦·库玛(Arun Kumar)

解决方法:

根据EncryptedStringType的javadocs:

A Hibernate 3 UserType implementation which allows transparent
encryption of String values during persistence of entities.

并根据Hibernate 4 Migration Guide

References to org.hibernate.usertype.UserType methods should be changed as indicated:

nullSafeGet(ResultSet rs, String[] names, Object owner) should be changed to
nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
nullSafeSet(PreparedStatement st, Object value, int index) should be changed to
nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)

因此jasypt 1.8与Hibernate 4.x不兼容.

您必须升级到jasypt 1.9,根据this的说法,它提供了Hibernate 4支持.

编辑:

Jasypt documentation提供了一个很好的概述.

第一句话:

Jasypt provides the jasypt-hibernate3 and jasypt-hibernate4 artifacts
for Hibernate integration. Since jasypt 1.9.0, these artifacts must be
added to your classpath separately.

因此,您需要将jasypt-hibernate4.jar添加到您的类路径中以解决编译错误.

上一篇:【论文泛读150】面试官 - 候选人角色扮演:走向开发真实世界的 NLP 系统


下一篇:Smack登录,注册,搜索用户,双向好友的建立,显示好友列表总结