Having a problem getting my @Before Aspect to not cause havock upon Spring startup. Removing the @Before but leaving the @Aspect allows Spring to start.
applicationContext.xml
CurrentStudyIdAspectCode:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd" default-autowire="byName"> <!-- Enable annotation config --> <context:annotation-config/> <!-- Enable AOP annotations --> <aop:aspectj-autoproxy/> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <value>classpath:jdbc.properties</value> </property> <property name="ignoreResourceNotFound" value="true"/> </bean> <!-- Transaction behavior based on annotations --> <tx:annotation-driven order="200"/> <!-- Data source --> <bean id="targetDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" depends-on=" "> <property name="driverClassName" value="${jdbc.driverClassName}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <property name="maxActive" value="100"/> <property name="maxWait" value="500"/> <property name="validationQuery" value="SELECT SYSDATE FROM DUAL"/> </bean> <bean id="dataSource" class="com.mycompany.commons.data.datasource.CurrentStudyIdAwareDataSourceProxy"> </bean> <!-- Hibernate --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="annotatedClasses"> <list> <value>com.mycompany.domain.Study</value> <value>com.mycompany.domain.User</value> <value>com.mycompany.domain.WebServiceSession</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="hibernate.use_sql_comments">${hibernate.use_sql_comments}</prop> <prop key="hibernate.max_fetch_depth">3</prop> </props> </property> </bean> <!-- Transaction --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"/> <!-- DAOs --> <bean id="siteDAO" class="com.mycompany.commons.data.dao.impl.SiteDAOGenericHibernateImpl"/> <bean id="userDAO" class="com.mycompany.commons.data.dao.impl.UserDAOGenericHibernateImpl"/> <bean id="webServiceSessionDAO" class="com.mycompany.commons.data.dao.impl.WebServiceSessionDAOGenericHibernateImpl"/> <bean id="studyDAO" class="com.mycompany.commons.data.dao.impl.StudyDAOGenericHibernateImpl"/> <!-- NativeJdbcExtractor for the Commons DBCP connection pool above --> <bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor" lazy-init="true"/> <!-- LobHandler for Oracle JDBC drivers --> <bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init="true"/> <!-- Aspects --> <bean class="com.mycompany.commons.data.support.CurrentStudyIdAspect"/> </beans>
CurrentStudyIdCode:package com.mycompany.commons.data.support; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.annotation.Order; import com.mycompany.commons.data.dao.WebServiceSessionDAO; import com.mycompany.domain.WebServiceSession; @Aspect @Order(100) public class CurrentStudyIdAspect { private static Log logger = LogFactory.getLog(CurrentStudyIdAspect.class); @Autowired private WebServiceSessionDAO webServiceSessionDAO; @Before("@annotation(com.mycompany.commons.data.annotation.CurrentStudyIdFromToken) && args(token, ..)") public void setCurrentStudyIdFromToken(byte[] token) { WebServiceSession session = webServiceSessionDAO.findByToken(token); if (token != null) { if (session != null) { if (session.getStudy() != null) { CurrentStudyIdHolder.setStudyId(session.getStudy().getId()); } else { logger.debug("session.study null"); } } else { logger.debug("session null"); } } else { logger.debug("token null or not size 16"); } } }
Code:package com.mycompany.commons.data.annotation; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(value = { ElementType.METHOD }) @Documented public @interface CurrentStudyIdFromToken { }


Reply With Quote