caused By:org.springframework.beans.factory.NoSuchBeanDefinitionException:No bean named ' App ' is defined

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.