Failed to instantiate [引用 spring 配置文件的类]: Constructor threw exception; nested exception is java.lang

Posted silense

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Failed to instantiate [引用 spring 配置文件的类]: Constructor threw exception; nested exception is java.lang相关的知识,希望对你有一定的参考价值。

本人的继承类引用了 service 层的方法,用的注解方式是@Autowired

该注解如果在容器 tomcat 启动后引用后不会报错,不会报 java.lang.NullPointerException 错误。

初始化时如果想调用数据库的数据,而此时 service 层的类没有实例化,导致 tomcat 启动时报空指针错误。

解决办法:

@Component
public class MessageResource extends AbstractMessageSource implements ResourceLoaderAware
{
@Autowired
private TsLanguageTestService tsLanguageTestService;

private static MessageResource util;

/**
* Map切分字符
*/
protected final String MAP_SPLIT_CODE = "|";
private final Map<String, String> properties = new HashMap<String, String>();

/**
* 初始化数据,把数据库里的国际化都读入缓存的Map里
*/
@PostConstruct
public void init() {
util = this;
util.tsLanguageTestService = this.tsLanguageTestService;
}
}

主要是 init() 方法和@PostConstruct 注解,这样 tomcat 启动时就会把@Autowired注解的类实体化


 






















以上是关于Failed to instantiate [引用 spring 配置文件的类]: Constructor threw exception; nested exception is java.lang的主要内容,如果未能解决你的问题,请参考以下文章

org.springframework.beans.BeanInstantiationException: Failed to instantiate [demo.Words]: No default

关于出现Failed to instantiate SLF4J LoggerFactory问题原因,解决办法

Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs.standard.tlv.JstlCoreTLV

FAILED: HiveException java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.me

FAILED: HiveException java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.me

解决Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient