Failed to instantiate [class referencing spring configuration file]: Constructor threw exception; Nested exception is java.lang.NullPointerException

Source: Internet
Author: User

My inheritance class refers to the service layer method, the annotated way is @autowired

The note will not report an error if it is referenced after the container tomcat is started, and java.lang.NullPointerException errors will not be reported.

If you want to invoke data from the database at initialization time, the service layer class is not instantiated, causing the tomcat to start the Times null pointer error.

Workaround:

@Component
public class Messageresource extends Abstractmessagesource implements Resourceloaderaware
{
@Autowired
Private Tslanguagetestservice Tslanguagetestservice;

private static Messageresource util;

/**
* Map Segmentation characters
*/
Protected final String Map_split_code = "|";
Private Final map<string, string> properties = new hashmap<string, string> ();

/**
* Initialize the data and read the internationalization of the database into the cached map
*/
@PostConstruct
public void init () {
Util = this;
Util.tslanguagetestservice = This.tslanguagetestservice;
}
}

is primarily the init () method and the @postconstruct annotation, so that the @autowired annotation class is manifested when Tomcat starts

Failed to instantiate [class referencing spring configuration file]: Constructor threw exception; Nested exception is java.lang.NullPointerException

Related Article

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.