【错误记录】@Override is not allowed when implementing interface method解决
2017-07-12 16:59
399 查看
今天在敲一个模拟Spring IOC的代码段的时候,遇到了如题所示的问题,还原情景:
一、类图:
可知:“AbstractBeanFactory”抽象类实现了“BeanFactory”接口,重写了其中的两个方法(见类图)。
错误代码如图:
奇怪,为什么之前在Eclipse中很常用的重写,在IDEA中就不行了,通过查资料,发现是maven插件没有配置的问题,如下。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
可见,我们在项目的pom.xml中,一般会有<build>下的许多<plugin>,常见的有
(1)maven-compiler-plugin
(2)maven-resources-plugin
(3)maven-source-plugin
(4)maven-javadoc-plugin
正是因为我在pom中缺少了其中的“maven-compiler-plugin”插件,导致了“@Override is not allowed when implementing interface method”这个问题。
分析:
“maven-compiler-plugin”的作用?
参考Apache官网对这个插件的介绍:http://maven.apache.org/components/plugins/maven-compiler-plugin/
The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.tools.JavaCompiler (if you are using java 1.6) and is used to compile Java sources. If you want to force the plugin using javac, you must configure the plugin option forceJavacCompilerUse.
Also note that at present the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with. If you want to change these defaults, you should set source and target as described in Setting the -source and -target of the Java Compiler.
Other compilers than javac can be used and work has already started on AspectJ, .NET, and C#.
NOTE: To know more about the JDK javac, please see: http://download.oracle.com/javase/6/docs/technotes/tools/windows/javac.html.
至于这个插件除了配置默认的JDK版本之外的功能还有啥,大家感兴趣的就去查查吧,对于上面4个常用的插件,可以比较一下异同。
一、类图:
可知:“AbstractBeanFactory”抽象类实现了“BeanFactory”接口,重写了其中的两个方法(见类图)。
错误代码如图:
奇怪,为什么之前在Eclipse中很常用的重写,在IDEA中就不行了,通过查资料,发现是maven插件没有配置的问题,如下。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
可见,我们在项目的pom.xml中,一般会有<build>下的许多<plugin>,常见的有
(1)maven-compiler-plugin
(2)maven-resources-plugin
(3)maven-source-plugin
(4)maven-javadoc-plugin
正是因为我在pom中缺少了其中的“maven-compiler-plugin”插件,导致了“@Override is not allowed when implementing interface method”这个问题。
分析:
“maven-compiler-plugin”的作用?
参考Apache官网对这个插件的介绍:http://maven.apache.org/components/plugins/maven-compiler-plugin/
The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.tools.JavaCompiler (if you are using java 1.6) and is used to compile Java sources. If you want to force the plugin using javac, you must configure the plugin option forceJavacCompilerUse.
Also note that at present the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with. If you want to change these defaults, you should set source and target as described in Setting the -source and -target of the Java Compiler.
Other compilers than javac can be used and work has already started on AspectJ, .NET, and C#.
NOTE: To know more about the JDK javac, please see: http://download.oracle.com/javase/6/docs/technotes/tools/windows/javac.html.
至于这个插件除了配置默认的JDK版本之外的功能还有啥,大家感兴趣的就去查查吧,对于上面4个常用的插件,可以比较一下异同。
相关文章推荐
- 一些错误和异常的解决方法02_@Override is not allowed when implementing interface method
- maven打包错误: -source 1.5 中不支持 diamond 运算符以及@Override is not allowed when implementing interface method
- IDEA提示@Override is not allowed when implementing interface method
- @Override is not allowed when implementing interface method
- IntelliJ IDEA 报错:@Override is not allowed when implementing interface method
- @Override is not allowed when implementing interface method
- IDEA @Override is not allowed when implementing interface method
- idea导入maven项目 报“Override is not allowed when implementing interface method”
- @Override is not allowed when implementing interface method
- @Override is not allowed when implementing interface method
- @Override is not allowed when implementing interface method
- @override is not allowed when implementing interface method
- @Override is not allowed when implementing interface method
- Idea @Override is not allowed when implementing interface method
- idea @Override is not allowed when implementing interface method
- idea @Override is not allowed when implementing interface method
- Intellij Idea @Override is not allowed when implementing interface method
- idea @Override is not allowed when implementing interface method
- @Override is not allowed when implementing interface method
- idea @Override is not allowed when implementing interface method