java-Normal class file @autowired automatically injected as null

Source: Internet
Author: User

@Autowired annotations are injected as NULL in the non-controller

1. Configuration files (packages where class files are located)

<base-package= "Net.nblh.utils.common"/>

2. class files

About @postconstruct: The method modified by @postconstruct will run when the server loads the servlet and will only be called once by the server, similar to the Serclet Inti () method. Methods that are modified by @postconstruct will run before the Init () method after the constructor.

@Component//declaration as spring component Public classGetspeechrecognitioninfo {@AutowiredPrivateIconfdayservice Confdayservice; //Static first-order current class     Public StaticGetspeechrecognitioninfo Getspeechrecognitioninfo; //annotation @postconstruct, so that the method is executed by the spring container after the bean is initialized@PostConstruct Public voidinit () {Getspeechrecognitioninfo= This; }     Public Static voidsyncdocument (String topicid) {List<TopicFile> fileList = getSpeechRecognitionInfo.confdayService.getConfFileByIssue (TopicID);//List of topic materials    }}

java-Normal class file @autowired automatically injected as null

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.