我使用 jdk 8 但 Spring 告诉我我需要 jdk 5 或更高版本

I use jdk8 but Spring told me I need jdk5 or higher

在.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

为什么?

在cmd中

C:\Users\idea>java -version

java version "1.8.0_45"

Java(TM) SE Runtime Environment (build 1.8.0_45-b15)

Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

尝试将此代码添加到项目的 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>