我使用jdk8但Spring告诉我需要jdk5或更高版本

时间:2015-08-31 07:21:11

标签: java spring version

在.java

System.out.println(System.getProperty("java.version"));

我得到了

  

1.8.0_45

但当我把它打包成jar包并在另一个项目中使用时它告诉我

Offending resource: class path resource [applicationContext.xml];
nested exception is
org.springframework.beans.factory.BeanDefinitionStoreException:
Unexpected exception parsing XML document from class path resource
[applicationContextYQ.xml]; nested exception is
java.lang.IllegalStateException: Context namespace element
'component-scan' and its parser class
[org.springframework.context.annotation.ComponentScanBeanDefinitionParser]
are only available on JDK 1.5 and higher

为什么呢?

in cmd

  

C:\ Users \ idea> java -version

     

java版本" 1.8.0_45"

     

Java(TM)SE运行时环境(版本1.8.0_45-b15)

     

Java HotSpot(TM)64位服务器VM(内置25.45-b02,混合模式)

1 个答案:

答案 0 :(得分:0)

尝试将此代码添加到项目的pom.xml中:

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
 <configuration>
    <source>1.8</source>
    <target>1.8</target>
    <compilerArgument />
    </configuration>
</plugin>

并且还要包含对JAR的所有依赖项:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptors>
                    <descriptor>src/assembly/assembly.xml</descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <id>package-all</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
</plugin>

在src / assembly下有assembly.xml(或根据需要更改路径):

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
    <id>jar-with-dependencies</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <useProjectArtifact>true</useProjectArtifact>
            <unpack>true</unpack>
            <scope>runtime</scope>
        </dependencySet>
    </dependencySets>
</assembly>