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_NAME
和BY_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
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 enterprise: Spring Java EE integration, Spring Integration, Spring Batch, jBPM with Spring, Spring Remoting, messaging, transactions, scaling using Terracotta and GridGrain, and more. ...
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...
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 ...
将runtime.exec()的四个陷阱用中文描述
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 ...
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 ...
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参考指南 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 ...
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 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 ...
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
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—...
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 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 ...
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.
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. ...