File tree Expand file tree Collapse file tree 7 files changed +99
-0
lines changed
spring-core-Import-ImportResource Expand file tree Collapse file tree 7 files changed +99
-0
lines changed Original file line number Diff line number Diff line change 3030 <module >spring-aop-10-inter-type-declarations</module >
3131 <module >spring-core-null-safety</module >
3232 <module >spring-core-work-with-resources</module >
33+ <module >spring-core-Import-ImportResource</module >
3334 </modules >
3435
3536 <properties >
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <project xmlns =" http://maven.apache.org/POM/4.0.0"
3+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
5+ <parent >
6+ <artifactId >spring-framework-tutorial-parent</artifactId >
7+ <groupId >com.jstobigdata</groupId >
8+ <version >1.0-SNAPSHOT</version >
9+ </parent >
10+ <modelVersion >4.0.0</modelVersion >
11+ <artifactId >spring-core-Import-ImportResource</artifactId >
12+ <description >Learn about Import and ImportResource annotations</description >
13+
14+ <dependencies >
15+ <dependency >
16+ <groupId >org.springframework</groupId >
17+ <artifactId >spring-core</artifactId >
18+ </dependency >
19+
20+ <dependency >
21+ <groupId >org.springframework</groupId >
22+ <artifactId >spring-context</artifactId >
23+ </dependency >
24+ </dependencies >
25+
26+ <dependencyManagement >
27+ <dependencies >
28+ <dependency >
29+ <groupId >com.jstobigdata</groupId >
30+ <artifactId >spring-tutorial-boms</artifactId >
31+ <version >1.0-SNAPSHOT</version >
32+ <type >pom</type >
33+ <scope >import</scope >
34+ </dependency >
35+ </dependencies >
36+ </dependencyManagement >
37+
38+ </project >
Original file line number Diff line number Diff line change 1+ package com .jbd .sc .importannotation ;
2+
3+ import com .jbd .sc .items .offline .OfflineOrderProcessor ;
4+ import com .jbd .sc .items .offline .OfflineStoreConfig ;
5+ import com .jbd .sc .items .online .OnlineOrderProcessor ;
6+ import org .springframework .context .ApplicationContext ;
7+ import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
8+ import org .springframework .context .annotation .Configuration ;
9+ import org .springframework .context .annotation .Import ;
10+ import org .springframework .context .annotation .ImportResource ;
11+
12+ @ Configuration
13+ @ Import (OfflineStoreConfig .class )
14+ @ ImportResource ("classpath:online-store-config.xml" )
15+ public class ApplicationConfig {
16+
17+ public static void main (String [] args ) {
18+ ApplicationContext context
19+ = new AnnotationConfigApplicationContext (ApplicationConfig .class );
20+
21+ context .getBean (OfflineOrderProcessor .class ).processOrder ("Book" );
22+ context .getBean (OnlineOrderProcessor .class ).processOrder ("Mobile Phone" );
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ package com .jbd .sc .items .offline ;
2+
3+ public class OfflineOrderProcessor {
4+ public void processOrder (String item ) {
5+ System .out .println ("Offline order processed: " + item );
6+ }
7+ }
Original file line number Diff line number Diff line change 1+ package com .jbd .sc .items .offline ;
2+
3+ import org .springframework .context .annotation .Bean ;
4+ import org .springframework .context .annotation .Configuration ;
5+
6+ @ Configuration
7+ public class OfflineStoreConfig {
8+
9+ @ Bean
10+ public OfflineOrderProcessor offlineOrderProcessor () {
11+ return new OfflineOrderProcessor ();
12+ }
13+ }
Original file line number Diff line number Diff line change 1+ package com .jbd .sc .items .online ;
2+
3+ public class OnlineOrderProcessor {
4+ public void processOrder (String item ) {
5+ System .out .println ("Online order processed: " + item );
6+ }
7+ }
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <beans xmlns =" http://www.springframework.org/schema/beans"
3+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4+ xsi : schemaLocation =" http://www.springframework.org/schema/beans
5+ http://www.springframework.org/schema/beans/spring-beans.xsd" >
6+
7+ <bean id =" onlineOrderProcessor" scope =" singleton"
8+ class =" com.jbd.sc.items.online.OnlineOrderProcessor" />
9+ </beans >
You can’t perform that action at this time.
0 commit comments