How can I fix this issue "Failed to load ApplicationContext"?

Hi all! Recently, I want to test my module controller, but it reported this error, and the following figure shows my test code.

So, can anyone tell me how to fix this problem?

hey @d404d may you please check the error-link

I think there is no problem with it.

I can use it

I changed some parts of the code, but it reported the same error.

@d404d When I try to view the error you’re reporting, I get this:

So, it’s not really possible to see what the error is. You can probably see the same error message if you try to access that URL via a private window. Maybe try posting the error log as as Gist on GitHub?

Thank you for the reminder! And I have put on the Gist.

I tried to add the ContextConfiguration directly, but still can’t work :scream_cat:

can we look at this entire class of yours Project1Activator.class

Yes, please.

But, is there any relationship between the Project1Activator and Project1Controller?

Which version of the JDK are you compiling with? And what JDK version are you targetting in your pom.xml? For the most part, when working on OMRS, you’ll need to target JDK 8, if not just use JDK 8, unless your project depends on openmrs-core 2.4.0 or later and any other modules you depend on are updated to recent versions.

PS The error I see in the Gist (thanks for that!) is this:

ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet

Hi Ian, thanks for your answer! Actually, I and my team members are using the JDK 8 and the version of openmrs-core is 2.4.0. So do I need to update the pom.xml?

And when your IDE launches the test, it’s definitely using JDK 8?

Yes, it is. This is my project structure.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.openmrs.maven.parents</groupId>
        <artifactId>maven-parent-openmrs-module</artifactId>
        <version>1.1.0</version>
    </parent>

	<groupId>org.openmrs.module</groupId>
	<artifactId>project1</artifactId>
	<version>1.0.0-SNAPSHOT</version>
	<packaging>pom</packaging>
	<name>Project1</name>
	<description>no description</description>

	<url>https://wiki.openmrs.org/x/FQ4z</url>

	<scm>
		<connection>scm:git:git@github.com:openmrs/openmrs-module-project1.git</connection>
		<developerConnection>scm:git:git@github.com:openmrs/openmrs-module-project1.git</developerConnection>
		<url>https://github.com/openmrs/openmrs-module-project1/</url>
	</scm>

	<modules>
		<module>api</module>
		<module>omod</module>
	</modules>

	<dependencyManagement>
		<dependencies>
			<!-- Importing versions from refapp distro -->
            <dependency>
                <groupId>org.openmrs.distro</groupId>
                <artifactId>referenceapplication</artifactId>
                <version>2.4</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
		</dependencies>
	</dependencyManagement>

	<repositories>
		<repository>
			<id>openmrs-repo</id>
			<name>OpenMRS Nexus Repository</name>
			<url>http://mavenrepo.openmrs.org/nexus/content/repositories/public</url>
		</repository>
		<repository>
			<id>central</id>
			<name>Maven Repository Switchboard</name>
			<layout>default</layout>
			<url>http://repo1.maven.org/maven2</url>
		</repository>
	</repositories>
	<pluginRepositories>
		<pluginRepository>
			<id>openmrs-repo</id>
			<name>OpenMRS Nexus Repository</name>
			<url>http://mavenrepo.openmrs.org/nexus/content/repositories/public</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</pluginRepository>
	</pluginRepositories>

	<properties>
		<openmrsPlatformVersion>1.11.6</openmrsPlatformVersion>
	</properties>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.6.1</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
		</plugins>
	</build>

</project>

And this is my pom.xml file. Does anyone know what should I add to make sure the version of asm can match my jdk?

Ah… if you’re targeting platform 1.11 (or really 1.x) you need to compile for Java 7 rather than Java 8. If you want to use Java 8 features, you probably need to target a minimum of OpenMRS 2.0.0.

OK, I will try to update it. Thank you

Sorry, you mean this part

	<properties>
		<openmrsPlatformVersion>1.11.6</openmrsPlatformVersion>
	</properties>

Yes… if you change that to 2.0.0, it should support Java 8

1 Like

Hi Ian, I changed the openmrsPlatformVersion to 2.0.0.

	<properties>
		<openmrsPlatformVersion>2.0.0</openmrsPlatformVersion>
	</properties>

But, I meet a new problem, that this module can not find out this dependency.