日期:2014-05-17  浏览次数:20644 次

用@component的bean id, 在spring配置文件app.context.html中的引用
@Component
@Transactional
public class SchedulingTasks {
   
    final Logger logger = Logger.getLogger(SchedulingTasks.class);
   
    @Autowired
    PtlCodeDao ptlCodeDao;
   
}

在spring的配置文件app.context.xml中想引用这个SchedulingTasks,如果像上面的@Component没有后面跟名字的,则bean id 默认为头字母小写schedulingTasks.

@Autowired也可以正常用

===========================
@Component("up.portal.util.SchedulingTasks")
@Transactional
public class SchedulingTasks {
   
    final Logger logger = Logger.getLogger(SchedulingTasks.class);
   
    @Autowired
    PtlCodeDao ptlCodeDao;
   
}

在spring的配置文件app.context.xml中想引用这个SchedulingTasks,如果像上面的@Component后面跟名字"up.portal.util.SchedulingTasks"的,则bean id 为@Component的名字"up.portal.util.SchedulingTasks",如:

<!-- 清除过时的认证码 -->
    <bean id="rmCodeShedule"
    class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    <property name="targetObject" ref="up.portal.util.SchedulingTasks" />
    <property name="targetMethod" value="timeRemoveCode" />
    <property name="concurrent" value="false" />
    </bean>