在代码中通过@PostConstruct指定bean的初始化调用方法,但是运行后发现该方法并没有被调用。
解决方法:在xml配置文件中加入一条指示符,让Spring处理相应的Annotation。
<beans xmlns=”http://www.springframework.org/schema/beans”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xmlns:context=”http://www.springframework.org/schema/context”
xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd“>
<context:annotation-config />
粗体部分是需要加入的与context相关的命名空间。