【问题标题】:I use jdk8 but Spring told me I need jdk5 or higher我使用 jdk8 但 Spring 告诉我我需要 jdk5 或更高版本
【发布时间】:2015-08-31 07:21:11
【问题描述】:

在.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 版本“1.8.0_45”

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

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

【问题讨论】:

  • 如何打包编译?
  • 你在 IDE 项目中检查过你的jdk 版本了吗?
  • @SanKrish 1.7 对于这个项目
  • 你确定吗?您使用哪个 IDE?检查编译器设置
  • 不要将代码、xml 等添加为 cmets。用这些信息改进你的问题。还可以使用mvn dependency:tree 检查您的库。

标签: java spring version


【解决方案1】:

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

【讨论】:

  • 我有这个conf,我认为eclipse没有将依赖打包到jar中,所以jar太小了
  • 尝试将此添加到 assembly.xml:&lt;files&gt; &lt;file&gt; &lt;source&gt;*.xml&lt;/source&gt; &lt;fileMode&gt;0644&lt;/fileMode&gt; &lt;outputDirectory&gt;./&lt;/outputDirectory&gt; &lt;/file&gt; &lt;file&gt; &lt;source&gt;*.config&lt;/source&gt; &lt;fileMode&gt;0644&lt;/fileMode&gt; &lt;outputDirectory&gt;./&lt;/outputDirectory&gt; &lt;/file&gt; &lt;/files&gt;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-24
相关资源
最近更新 更多