【错误记录】@Override is not allowed when implementing interface method解决

        今天在敲一个模拟Spring IOC的代码段的时候,遇到了如题所示的问题,还原情景:


        一、类图:

【错误记录】@Override is not allowed when implementing interface method解决_第1张图片

          可知:“AbstractBeanFactory”抽象类实现了“BeanFactory”接口,重写了其中的两个方法(见类图)。


          错误代码如图:

     【错误记录】@Override is not allowed when implementing interface method解决_第2张图片

       奇怪,为什么之前在Eclipse中很常用的重写,在IDEA中就不行了,通过查资料,发现是maven插件没有配置的问题,如下。


        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                3.1
                
                    1.8
                    1.8
                    UTF-8
                
            
            
                org.apache.maven.plugins
                maven-resources-plugin
                2.6
                
                    UTF-8
                
            
            
                org.apache.maven.plugins
                maven-source-plugin
                2.2.1
                
                    
                        attach-sources
                        
                            jar
                        
                    
                
            
            
                org.apache.maven.plugins
                maven-javadoc-plugin
                2.9.1
                
                    UTF-8
                
                
                    
                        attach-javadocs
                        
                            jar
                        
                    
                
            
        
    
         
        可见,我们在项目的pom.xml中,一般会有下的许多,常见的有

      (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个常用的插件,可以比较一下异同。

       



你可能感兴趣的:(【错误记录】@Override is not allowed when implementing interface method解决)