1

I am using aspectJ class for Exception Handling aspect in Spring. i need to read values from properties files which is defined in spring bean. Presently I am reading property file using the context. is there any other option. earlier while i was using spring aop ,proxy object automatically read the properties file without accessing through the context.

Spring Config File

<bean id="applicationProperties"
    class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="location">
        <value>classpath:/resources/config/application.properties</value>
    </property>
</bean>

public Properties exceptionProp = null;

ExceptionHandlingAspect Class(i have to use context for reading propeties here)

 public class ExceptionHamdlingAspect{

public void setExceptionProp(Properties exceptionProp) {
    this.exceptionProp=exceptionProp;
}

 @AfterThrowing(pointcut = "ExceptionHandlingAspect()", throwing = "ex")
public void logAfterThrowingException(final JoinPoint currentJp,
        Throwable ex) throws Exception {

ApplicationContext ctx = AppContext.getApplicationContext();
this.exceptionProp=(Properties) ctx.getBean("applicationProperties");   


PropertyReader.getValueForProperty(ex.getClass().getSimpleName(),exceptionProp);
System.out.println("error values :"+errorString[0]+ errorString[1]);


}

 }
Cœur
  • 37,241
  • 25
  • 195
  • 267
Vish
  • 867
  • 6
  • 19
  • 45

1 Answers1

3

You can wire up your aspect using the static aspectOf factory method (you can't see that method, it is added by the aspectj compiler)

<bean class="com.YourAspect" factory-method="aspectOf">
    <property name="exceptionProp"
              value="classpath:path/to/propfile.properties" />
</bean>

Reference:

Community
  • 1
  • 1
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
  • i have added a new [question](http://stackoverflow.com/questions/6531722/not-able-to-use-request-scope-in-the-spring-config-file).please go throught it – Vish Jun 30 '11 at 08:07