来源 :http://www.jroller.com/habuma/date/20070516
spring 2.0 配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="quest"
class="com.springinaction.chapter01.knight.HolyGrailQuest"/>
<bean id="knight"
class="com.springinaction.chapter01.knight.KnightOfTheRoundTable">
<constructor-arg value="Bedivere" />
<property name="quest" ref="quest" />
</bean>
<bean id="minstrel"
class="com.springinaction.chapter01.knight.Minstrel"/>
<aop:config>
<aop:aspect ref="minstrel">
<aop:pointcut
id="questPointcut"
expression="execution(* *.embarkOnQuest(..)) and target(bean)" />
<aop:before
method="singBefore"
pointcut-ref="questPointcut"
arg-names="bean" />
<aop:after-returning
method="singAfter"
pointcut-ref="questPointcut"
arg-names="bean" />
</aop:aspect>
</aop:config>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.1.xsd">
<context:component-scan
base-package="com.springinaction.chapter01.knight" />
</beans>
<context:component-scan> is a new configuration element in the "context" namespace (which, BTW, is also new in Spring 2.1). This modest little element tells Spring to scan the "com.springinaction.chapter01.knight" package (as specified by the base-package attribute) and any subpackage looking for classes that might be annotated with @Component (new in Spring 2.1), @Repository (new in Spring 2.0), or @Aspect (provided by @AspectJ). If it finds any such class, it automatically will register the class as a bean in the Spring application context. So, although <context:component-scan> takes up so very little space in the XML configuration, it could be responsible for configuring dozens, hundreds, or even thousands of beans in Spring.
@Component tells Spring that this class should be automatically registered in the Spring context. By default, the class name is used as the bean's ID, but here I've explicitly specified that the bean should have an ID of "knight".
@Autowired
private Quest quest;
Next, notice that the setQuest() method is annotated with
@Autowired. This tells Spring that this setter shold automatically be wired with a bean reference. The autowiring is "byType", so there will need to be a Quest bean in the Spring context. There's not one there now, but I'll add one soon.
package com.springinaction.chapter01.knight;
import org.springframework.stereotype.Component;
@Component
public class HolyGrailQuest implements Quest {
public void embark() {
System.out.println("Embarking on the quest for the Holy Grail!");
}
}
@Resource(name="grailQuest")
public void setQuest(Quest quest) {
this.quest = quest;
}
分享到:
相关推荐
This book is short, about 260 pages. The topics I have covered include: 1) Using JAX-RS annotations to construct a web service which is accessible with a URL created using the same annotations. 2) ...
My Batis can use simple XML or Annotations for configuration and map primitives, Map interfaces and Java POJOs (Plain Old Java Objects) to database records. 1.1.2 Help make this documentation better...
Preface xxi Part I: Introduction 1 Chapter 1: Overview 3 Java EE 6 Platform Highlights...Metadata Annotations 538 Common Client Interface 540 Further Information about Resources 541 Index 543
Following this, you will come across recipes that will help you to compose static maps, create heavily customized maps, and add specialized labels and annotations. Apart from this, the book will also...
You'll find best practices on selecting sample data for human feedback, quality control for human annotations, and designing annotation interfaces. You'll learn to create training data for labeling, ...
AnnotationMap A map of annotations used with ComponentDefinition and ComponentInfo. AttributesInfo Represents a map of custom attributes of a component definition (ComponentDefinition). ...
The FDA continues to be concerned about evaluating noncardiac drugs for negative cardiac effects, like prolonged QT. Before this initiative, sponsors were already submitting ECG findings tabulations ...
based transaction-type applications that access complex data with Hibernate How to work with Hibernate 4 Where to integrate into the persistence life cycle How to map using annotations, Hibernate XML ...
learn about the inter-modal correspondences between language and visual data. Our alignment model is based on a novel combination of Convolutional Neural Networks over image regions, bidirectional ...
More about assisted injections in the Guice wiki. Usage class MyPresenter { @AssistedInject MyPresenter(Long foo, @Assisted String bar) {} @AssistedInject.Factory interface Factory { ...
Component and transformer annotations quick reference Appendix C. Mule Enterprise Edition Appendix D. A sample Mule application Book Details Title: Mule in Action, 2nd Edition Author: David Dossot, ...
Following that, you will learn about unsupervised learning algorithms such as Autoencoders and the very popular Generative Adversarial Networks (GAN). You will also explore non-traditional uses of ...
classification of images into different categories, and advanced objects recognition with related image annotations. An example of identification of salient points for face detection is also provided...
This book is about EJB 3, the shiny new version of the Enterprise Java- Beans standard. The timely rebirth of EJB is made possible through innovations introduced in Java SE 5, such as metadata ...
classification of images into different categories, and advanced objects recognition with related image annotations. An example of identification of salient points for face detection is also provided...
Further on, you’ll learn about advanced technologies that Java delivers, such as web programming and parallel computing, and will develop a mastermind game. Moving on, we provide more simple ...
classification of images into different categories, and advanced objects recognition with related image annotations. An example of identification of salient points for face detection is also provided...