In the use of spring-test When , Start up @Test Method time ,spring-test Will load spring Configuration file for , At this time, if the configuration file is not in  @ContextConfiguration  All in Chinese , Will cause the load to fail halfway , Then throw  java.lang.IllegalStateException: Failed to load ApplicationContext  It's abnormal , And then lead to the priority loading of various bean Loading failed

abnormal ：

[main] WARN org.springframework.web.context.support.GenericWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'assetParser' defined in file [D:\project2\RM\target\classes\org\kinome\rm\utils\file\AssetParser.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.kinome.rm.utils.file.AssetParser]: Constructor threw exception; nested exception is java.lang.NullPointerException
[main] ERROR org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@f2f2cc1] to prepare test instance [MvcTest@6d469831]
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)

resolvent ：

Only need  @ContextConfiguration  Zhongba （idea）resources All under spring The configuration file name is completely written , It won't be because you can't load what you haven't written spring Failed to load the configuration file , Write all the configuration files successfully, and then load all the configuration files successfully

example ：

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = {"classpath:applicationContext.xml", "classpath:spring-servlet.xml"}) // Because there's no applicationContext-quartz.xml The configuration file is loaded in , So it leads to the occurrence of anomalies
public class MvcTest {
}

Only need to  applicationContext.xml  Change to  applicationContext*.xml  You can put the  applicationContext-quartz.xml  Loaded in , It's going to work .

If new ones are added in the future spring file , Also pay attention to spring-test Of  @ContextConfiguration  To bring in .

In the future, I will spring The unified format of all configuration files is ：applicationContext（ Add other names to distinguish spring The configuration file ）.xml , thus , One  applicationContext*.xml  It's all brought in , There's no need to change web.xml  and  spring-test  Or other dependencies spring Import items that need to be imported in the configuration file The introduction of .

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = {"classpath:applicationContext*.xml", "classpath:spring-servlet.xml"})
public class MvcTest {
}

## solve spring-test appear Failed to load ApplicationContext More articles about the exception of

1. java.lang.IllegalStateException: Failed to load ApplicationContext selenium abnormal solve

WARN <init>, HHH000409: Using org.hibernate.id.UUIDHexGenerator which does not generate IETF R ...

2. spring junit Unit test , newspaper Failed to load ApplicationContext error

spring junit Unit test , newspaper Failed to load ApplicationContext error . For a while , Finally found .@ContextConfiguration(locatio ...

3. spring in junit Tips Failed to load ApplicationContext

Error message : 1:java.lang.IllegalStateException: Failed to load ApplicationContext 2:Error creating bean wit ...

4. small SSM The project appears Failed to load ApplicationContext The wrong solution （ Personally to ）

When using unit testing , There is Failed to load ApplicationContext error , A new one has been added in Mapper.xml It's just the files that show up , In the case of ensuring that there are no errors in other configuration files , Check mapper ...

Cause condition : WebSocket+ unit testing , Unit test error ! resolvent : SpringBootTest increase webEnvironment Parameters . https://docs.spring.io/spring-b ...

Cause condition : SpringBoot2.0 Next yml File configuration SLF4j Log output log level logging: level: debug resolvent : Specify the system package path logging: root: debug Appoint ...

Error message : Caused by: java.lang.IllegalArgumentException: Mapped Statements collection already contains v ...

8. Integrate JUnit Test error java.lang.IllegalStateException: Failed to load ApplicationContext

1 Detailed error information java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.t ...

9. Spring3.x Version and JDK1.8 Incompatibility causes java.lang.IllegalStateException: Failed to load ApplicationContext

Due to the installation of JDK1.8 Version of , There's been consolidation recently Struts2+Spring+Hibernate Frame time , Accidentally imported the previously downloaded Spring 3.2.0 Version of jar package . The results are used to run the test ...

## Random recommendation

1. ABP The cache of theoretical learning Caching

Return to the general catalog This directory Introduce ICacheManager ICache ITypedCache To configure Introduce ABP Provides an abstraction for caching , It uses this cache abstraction internally . Although the default implementation uses MemoryCache, ...

2. LintCode &quot;Expression Evaluation&quot;

This is sth. for me to learn.. https://github.com/kamyu104/LintCode/blob/master/C++/expression-evalu ...

3. About Filezilla Do you support sftp

We know filezilla It's an open source ftp Solutions for , It provides both the client side and the server side , Supported by fpt, sftp, ftps, This is what you can get from wiki What you see in filezilla Introduction to , But here's one thing to clarify ...

4. jsp or Action Get the request parameter Chinese garbled

In general , Chinese characters are automatically converted to iso-8859-1 The coding format is transmitted over the network , This format can't directly express the Chinese characters we know , So you have to manually convert it back to the previous character set . Generally in servlet perhaps actio ...

5. .NET Basics —— Array

This article , Let's see C# In the array . 1. The concept of array Array : A container for storing multiple data elements of the same type Array declaration and initialization : When creating arrays , You must specify the length of the array ]; ,, }; ] { , , };// Of array elements ...

6. Keepalived Installation and configuration

Download and unzip Keepalived Install the package to two nginx Server   192.168.200.1   192.168.200.2     Perform compilation and installation ( The installation directory is set to /usr/local/kee ...

7. Research analysis JS Three logical statements in

JS Three logical statements in : The order . Branch and loop statements . One . Sequential statements The code specification is as follows :1. <script type="text/javascript"> var a = 10;  ...

1. About read Compare the sizes of the two #!/bin/sh read -t -p "please input two num:" a b if [ $a -gt$b ]; then ec ...