Spring and Mendix

0
Is it possible to use Spring in a Mendix Java Action? I attempted to load a Spring context file in a Java Action, but it can't find classes that are in jar files from the userlib folder. In Eclipse these files are definitely in the classpath. Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.ws.client.core.WebServiceTemplate] for bean with name 'imageAccessTemplate' defined in file [C:\Users\user\Documents\project\deployment\model\resources\ImageAccessContext.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.ws.client.core.WebServiceTemplate not found by mxruntime [39]
asked
2 answers
1

The problem was how I was loading Spring. Using ClassPathXmlApplicationContext does not work.

You must specify an alternative classloader that can see the libraries in /userlib.

Instead I followed the advice from this answer using a class that was in the same library where my Spring configuration was defined.

final ClassLoader clientClassLoader = SomeSpringBean.class.getClassLoader();

ApplicationContext context = new ClassPathXmlApplicationContext("classpath:SpringContext.xml") {

    @Override
    protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
        super.initBeanDefinitionReader(reader);
        reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
        reader.setBeanClassLoader(clientClassLoader);
        setClassLoader(clientClassLoader);
    }
};
answered
0

Have you added the following Java library to your project's userlib directory?

http://mvnrepository.com/artifact/org.springframework.ws/spring-ws-core

answered