`
hypgr
  • 浏览: 273259 次
社区版块
存档分类
最新评论

AnnotationFormatError when using Spring 3.0 & JavaConfig

阅读更多

    Spring 3.0M3 及其以后的版本包含了JavaConfig 项目提供的大部分功能. 如果你的程序遭遇如下异常:

Exception in thread "main" java.lang.annotation.AnnotationFormatError: Invalid default: public abstract org.springframework.beans.factory.annotation.Autowire

  org.springframework.config.java.annotation.Configuration.defaultAutowire()

 

    这很可能是因为你在Classpath 中添加了JavaConfig 项目release 出来的包( 比如 org.springframework.config.java-1.0.0.M4.jar ), 而在程序中使用JavaConfigApplicationContext 类。查看org.springframework.config.java-1.0.0.M4.jar 包的source code, 你会发现org.springframework.config.java.annotation.Configuration 类的defaultAutowire 的定义如下:

Autowire defaultAutowire() default Autowire .INHERITED;

    而查看org.springframework.beans.factory.annotation.Autowire 枚举类,你会发现INHERITED 根本就没有定义( 只有NO, BY_NAMEBY_TYPE 三种) 。这就难怪会报错了。

 

    事实上,由于Spring 3.0M3 及其以后的版本包含了JavaConfig 项目提供的大部分功能,你无需为应用再添加JavaConfig 的包。@Configuration, @Bean 等都已经被整合到了org.springframework.context.annotation, 从文件来看就是org.springframework.context.jar 包。下图展示了一个可运行项目的Classpath 配置:


   由于没有了JavaConfig 项目release 的包, JavaConfigApplicationContext 类也就无法找到了,你需要将它替换成org.springframework.context.annotation.AnnotationConfigApplicationContext, 例如:

public static void main(String[] args) {

ApplicationContext context = new

AnnotationConfigApplicationContext(ApplicationConfig.class );

String x = context.getBean("x", String.class );

System.out .println("Got x: " + x);

}

分享到:
评论

相关推荐

    vue3.0 vue.config.js 配置实战.docx

    vue3.0 vue.config.js 配置实战.docx

    thymeleaf-extras-springsecurity-3.0-master.zip

    Finally, there is an attribute for checking authorization using Spring Security's Access Control Lists, which needs the specification of a domain object and the permissions defined on it that we are ...

    Spring Recipes: A Problem-Solution Approach, Second Edition

    * Spring enterprise: Spring Java EE integration, Spring Integration, Spring Batch, jBPM with Spring, Spring Remoting, messaging, transactions, scaling using Terracotta and GridGrain, and more. ...

    spring.microservices.in.action

    Chapter 3 introduces you to how to manage the configuration of your microser- vices using Spring Cloud Config. Spring Cloud Config helps you guarantee that your service’s configuration information is...

    [Spring] Spring LDAP 实践开发 (英文版)

    Practical Spring LDAP is your guide to developing Java-based enterprise applications using the Spring LDAP Framework. This book explains the purpose and fundamental concepts of LDAP before giving a ...

    when Runtime.exec() won't 中文翻译版

    将runtime.exec()的四个陷阱用中文描述

    Spring Microservices in Action.pdf

    Spring Microservices in Action teaches you how to build microservice-based applications using Java and the Spring platform. Purchase of the print book includes a free eBook in PDF, Kindle, and ePub ...

    Pivotal Certified Spring Web Application Developer Exam(Apress,2015)

    When you become a Pivotal Certified Spring Web Application Developer, you'll receive one of the most valuable credentials available in enterprise Java. Achieving this certification demonstrates your ...

    Android代码-Recyclerview-Gallery

    README 中文版文档 This library shows you a gallery using ...Third step, init your GalleryRecyclerView in your java code just like using the normal RecyclerView. Note that you must use the LinearLayou

    HBase3.0参考指南

    HBase3.0参考指南 This is the official reference guide for the HBase version it ships with. Herein you will find either the definitive documentation on an HBase topic as of its standing when the ...

    Spring 5 Design Patterns

    You will learn to use these design patterns to solve common problems when designing an application or system using the Spring Framework. This book will not only take you through the essential GoF ...

    Spring Python 1.1

    Spring Python is all about using the many useful features of Spring to the fullest and making these features available when working with Python. Get to grips with all of the concepts of Spring and ...

    Packt.Hands-On.Spring.Security.5.for.Reactive.Applications

    You will also understand how to achieve authorization in a Spring WebFlux application using Spring Security.You will be able to explore the security confgurations required to achieve OAuth2 for ...

    Z Trying to beat up the GDI when using DirectXDirecX和GDI

    Z Trying to beat up the GDI when using DirectXDirecX和GDI

    Spring Boot 2 Recipes: A Problem-Solution Approach

    Integrate enterprise services to create a more complex Java application using Spring Boot Who This Book Is For Experienced Java and Spring programmers. Table of Contents Chapter 1: Spring Boot—...

    Spring 5 Recipes, 4th Edition

    Other recipes include Spring enterprise solutions for topics such as Spring Java EE integration, Spring Integration, Spring Batch, Spring Remoting, messaging, transactions, and working with big data ...

    Java连接Oracle数据库驱动(各种版本)

    Java classes when using the JDBC Thin and OCI client-side driver - with Java 7.0 VM. ojdbc6.jar Java classes when using the JDBC Thin and OCI client-side driver - with Java 6.0 VM. ojdbc5.jar Java ...

    W5300参考资料,使用手册

    SUBJECT W5300 Reference Schematic NAME WIZnet DATE 2013-07-10 HIT 6921 This is the reference schematic of W5300 when using internal PHY & external PHY.

    spring-boot-reference.pdf

    13.2.2. Using Spring Boot without the Parent POM 13.2.3. Using the Spring Boot Maven Plugin 13.3. Gradle 13.4. Ant 13.5. Starters 14. Structuring Your Code 14.1. Using the “default” Package 14.2. ...

Global site tag (gtag.js) - Google Analytics