0

私はSpringに出くわしましたがPersistenceExceptionTranslationPostProcessor、これは で注釈が付けられたDAOでスローされる例外を抽象化するため、完璧に思え@Repositoryます。

現在、バックエンドとしてデータベースの代わりに JMS (ActiveMQ) を使用するアプリケーションがあります。s を Spring のPersistenceExceptionTranslationPostProcessorに変換するようなものを使用したいと思います。JMSExceptionDataAccessException

車輪を再発明する前に、そのようなものをウェブで検索しましたが、見つかりませんでした。間違った検索キーを使用している可能性があります。もう一度試してみると、このようなものが存在することを知っている人はいますか?それとも、このホイールを発明する必要がありますか?


アップデート:

私は自分自身を作成する必要があるようPersistenceExceptionTranslatorです。私は次のことをしました:

PersistenceExceptionTranslator私の抽象的なJM​​S DAOに実装されています:

public abstract class AbstractJmsDao implements PersistenceExceptionTranslator
{
    public void throwException()
    {
        try
        {
            throw new JMSException("test");
        }
        catch (JMSException ex)
        {
            throw JmsUtils.convertJmsAccessException(ex);
        }
    }

    @Override
    public DataAccessException translateExceptionIfPossible(RuntimeException ex)
    {
        // translate exceptions here.
    }
}

PersistenceExceptionTranslationPostProcessor私のXML構成に追加されました:

<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

私のDAO実装に次の注釈を付けました@Repository

@Repository
public class CustomerJmsDao extends AbstractJmsDao implements CustomerDao
{
    public void test()
    {
        throwException();
    }
}

ただし、 aRuntimeExceptionがスローされると、translateExceptionIfPossible()がヒットすることはありません (ブレークポイントでチェック)。ここで明らかに何かが欠けていますが、何がわかりません。

4

1 に答える 1

0

DataAccessException 階層の例外には変換されませんが、JmsUtils.convertJmsAccessException()Spring の同等のものに変換されます...

/**
 * Convert the specified checked {@link javax.jms.JMSException JMSException} to a
 * Spring runtime {@link org.springframework.jms.JmsException JmsException} equivalent.
 * @param ex the original checked JMSException to convert
 * @return the Spring runtime JmsException wrapping the given exception
 */
于 2013-01-07T16:54:56.823 に答える