I want to get value of systemType variable from login token everytime I access to API, so I've written an AOP class :
@Aspect
@Configuration
public class AspectDatabaseService {
Logger logger = LoggerFactory.getLogger(AspectDatabaseService.class);
public int systemType;
public int getSystemType() {
return systemType;
}
public void setSystemType(int systemType) {
this.systemType = systemType;
}
@Before("execution(* com.toshiba.mwcloud.gs.dbaas.service.impl.DatabaseServiceImpl.*(..))")
public void before(JoinPoint joinPoint) {
.....
systemType = getSystemTypeFromToken(token);
logger.info("before called {0}", joinPoint.toString());
}
private HttpServletRequest getHttpServletRequest() {
......
}
private int getSystemTypeFromToken(String token) {
......
}
}
And I have a class with constructor like this
public DatabaseServiceImpl(SingleDatabaseServiceImpl singleDatabaseService,
MultiDatabaseServiceImpl multiDatabaseServiceImpl, OperatorDatabaseServiceImpl operatorDatabaseServiceImpl,
AspectDatabaseService aspectDatabaseService) {
this.aspectDatabaseService = aspectDatabaseService;
this.systemType = aspectDatabaseService.getSystemType();
if (systemType == SystemType.SINGLE.getCode()) {
this.databaseAbstractService = singleDatabaseService;
} else if (systemType == SystemType.MULTI.getCode()) {
this.databaseAbstractService = multiDatabaseServiceImpl;
} else {
this.databaseAbstractService = operatorDatabaseServiceImpl;
}
}
But my AOP class is not worked, value of systemType in constructor of class DatabaseServiceImpl always returns 0 because Constructor still init before run AOP class
What should I do to change value in constructor ? Thanks a lot