如何在java中将xml加载到ClassPathXmlApplicationContext而不出错?

时间:2014-04-25 09:44:11

标签: java spring

我有java配置的xml文件,我无法加载bean javas中的文件

main.java:

ApplicationContext appContext = new ClassPathXmlApplicationContext("applicationContext.xml");
PDF2HTMLService service = appContext.getBean(PDF2HTMLService.class);

错误:

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - incompatible types: org.springframework.context.support.ClassPathXmlApplicationContext cannot be converted to org.springframework.context.ApplicationContext
    at pdf2html.Main.main(Main.java:27)
Java Result: 1

我该如何解决这个问题...

XML文件:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                        http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/context 
                        http://www.springframework.org/schema/context/spring-context.xsd
                        http://www.springframework.org/schema/aop 
                        http://www.springframework.org/schema/aop/spring-aop.xsd">

    <aop:aspectj-autoproxy />

    <context:component-scan base-package="pdf2html" />

</beans>

1 个答案:

答案 0 :(得分:1)

很奇怪。 ClassPathXmlApplicationContext implements ApplicationContext。可能是类路径问题。

ClassPathXmlApplicationContext从一个jar加载,ApplicationContext从另一个加载,它们不兼容版本。

检查类路径是否有spring-context-[VERSION].jar

的重复