Tools: Eclipse Mars
Environment: jdk1.8
Description: This is a bug encountered while learning Spring task, the code is as follows:
Timed Task class:
Packagecom.task.test;Importjava.util.Date;Importorg.springframework.stereotype.Component; @Component Public classApp { Public voidexecute1 () {System.out.printf ("Task:%s, Current time:%s\n", 1,NewDate () + "Current thread:" +Thread.CurrentThread (). GetName ()); } Public voidExecute2 () {System.out.printf ("Task:%s, Current time:%s\n", 2,NewDate () + "Current thread:" +Thread.CurrentThread (). GetName ()); }}
Spring configuration file:
<?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:context= "Http://www.springframework.org/schema/context"Xmlns:task= "Http://www.springframework.org/schema/task"xsi:schemalocation="http//Www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.1.xsdhttp//Www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.1.xsdhttp//Www.springframework.org/schema/taskhttp://www.springframework.org/schema/task/spring-task-4.1.xsd"><!--configuration annotations Scan-<context:component-scan base- Package= "Com.task.test"/> <task:scheduler id= "TaskScheduler" pool-size= "/> <task:scheduled-tasks Scheduler" = "TaskScheduler" > <!--start every 5 seconds to trigger a task once--<task:scheduled ref= "App" method= "execute1" cron= "0/5 * * * * ?" /> <!--start immediately, 10 seconds to trigger the task once--<task:scheduled ref= "App" method= "Execute2" cron= "0/10 * * * *?" /> </task:scheduled-tasks></beans>
Test code:
Packagecom.task.test;Importjava.util.Date;Importorg.springframework.stereotype.Component; @Component Public classApp { Public voidexecute1 () {System.out.printf ("Task:%s, Current time:%s\n", 1,NewDate () + "Current thread:" +Thread.CurrentThread (). GetName ()); } Public voidExecute2 () {System.out.printf ("Task:%s, Current time:%s\n", 2,NewDate () + "Current thread:" +Thread.CurrentThread (). GetName ()); }}
Action: Right-click the Eclipse Editor---> Tap Run as--->java application
Error:
Cause: The ref attribute in the spring configuration file deserves the name format to be the hump naming method, and the ref= "app" in the spring configuration file will be changed to ref= "app".
caused By:org.springframework.beans.factory.NoSuchBeanDefinitionException:No bean named ' App ' is defined