Skip to content

Audit by aspectj xml config doesn't work well, don't save on database (MySQL) by Annotation work fine #6

@argades

Description

@argades

Hello,
I have tested the demo audit4j-demo-spring-petclinic to use AOP for xml configuration and I have detected that version 2.4.1 does not save in database but using @Audit annotation does work. In 2.3.1 version does work but doesn't catch origin data.

To test the spring aspect configuration, I commented on the @Audit annotation of the saveOwner method of the ClinicServiceImpl.java class, although it does not have it by default.

//@Audit public void saveOwner(Owner owner) throws DataAccessException

xml configuration

<aop:aspectj-autoproxy/>

<bean id="auditAspect" class="org.audit4j.integration.spring.AuditAspect" lazy-init="true"/>

<bean id="auditManager" class="org.audit4j.core.AuditManager" factory-method="startWithConfiguration" lazy-init="true">
	<constructor-arg ref="auditconfig"/>
</bean>

<aop:config>  
	<aop:aspect id="aspect" ref="auditAspect" >
		<aop:pointcut id="pointCutSave" expression="execution(* *.save*(..))" />  
		<aop:before method="audit" pointcut-ref="pointCutSave" />  
	</aop:aspect>  
</aop:config>  

<bean id="layout" class="org.audit4j.core.layout.SimpleLayout"></bean>
<bean id="metaData" class="org.springframework.samples.petclinic.util.AuditMetaData"></bean>
<bean id="consoleAuditHandler" class="org.audit4j.core.handler.ConsoleAuditHandler"></bean>

<bean id="databaseAuditHandler" class="org.audit4j.handler.db.DatabaseAuditHandler">
    <property name="embedded" value="false"></property>
    <property name="separate" value="false"></property>
    <property name="db_connection_type" value="jndi"></property>
    <property name="db_jndi_datasource" value="java:/Audit4JDS"></property>
</bean>

<bean id="auditconfig" class="org.audit4j.integration.spring.SpringAudit4jConfig">
	<property name="layout" ref="layout"></property>
	<property name="metaData" ref="metaData"></property>
	<property name="handlers">
		<list>
			<ref bean="consoleAuditHandler" />
			<ref bean="databaseAuditHandler" />
		</list>
	</property>
</bean>

I have debugged the code in both cases and by annotations it goes through different methods and executes the method public boolean writeEvent (AuditEvent event) throws HandlerException but by aspect does not pass by there, therefore does not save the data in database.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions