@Value注释在某些方面可用于执行时不会将Spel结果注入属性。 当我从DbAspect注释掉建议或者尝试使用getter访问属性时,它工作正常。
代码是:
Application.java:
FragmentManager fm = getFragmentManager();
mapFragment = (MapFragment) fm.findFragmentById(R.id.map_container);
if (mapFragment == null) {
mapFragment = MapFragment.newInstance();
Log.d("CHECK_SPEED", "replace");
fm.beginTransaction().replace(R.id.map_container, mapFragment)
.setCustomAnimations(R.anim.fade_in, R.anim.fade_out, R.anim.fade_in, R.anim.fade_out)
.commit();
setupGoogleMap();
}
config.xml中:
package com.spring.demo;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Application {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("config.xml");
Dummy dummy = ctx.getBean(Dummy.class);
System.out.println(dummy.integer);
System.out.println(dummy.name);
System.out.println(dummy.map);
System.out.println(dummy.list);
}
}
DbAspect.java:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.spring.demo"/>
<aop:aspectj-autoproxy/>
</beans>
Dummy.java
package com.spring.demo;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class DbAspect {
@Before("execution(void *.*(..))")
void beforeAdvice() {
System.out.println("=======================args advice");
}
}
使用具有AOP duo的getter访问属性的弹簧约定是什么?