forked from TinaXing2012/Spring
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b933a9
commit e46500a
Showing
4 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
springautowiring/src/main/java/xing/rujuan/autowired/AppConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package xing.rujuan.autowired; | ||
|
||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ComponentScan("xing.rujuan.autowired") | ||
public class AppConfig { | ||
} |
12 changes: 12 additions & 0 deletions
12
springautowiring/src/main/java/xing/rujuan/autowired/AppMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package xing.rujuan.autowired; | ||
|
||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
|
||
public class AppMain { | ||
public static void main(String[] args) { | ||
ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class); | ||
CustomerService customerService = context.getBean("customerService", CustomerService.class); | ||
System.out.println(customerService.getCustomerDao()); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
springautowiring/src/main/java/xing/rujuan/autowired/CustomerDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package xing.rujuan.autowired; | ||
|
||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository("custdao") | ||
public class CustomerDao { | ||
} |
31 changes: 31 additions & 0 deletions
31
springautowiring/src/main/java/xing/rujuan/autowired/CustomerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package xing.rujuan.autowired; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class CustomerService { | ||
|
||
// @Autowired | ||
private CustomerDao customerDao; | ||
|
||
public CustomerService(){ | ||
System.out.println("default constructor...."); | ||
} | ||
|
||
@Autowired | ||
public CustomerService(CustomerDao customerDao) { | ||
System.out.println("customized constructor...."); | ||
this.customerDao = customerDao; | ||
} | ||
|
||
public CustomerDao getCustomerDao() { | ||
return customerDao; | ||
} | ||
|
||
// @Autowired | ||
public void setCustomerDao(CustomerDao customerDao) { | ||
System.out.println("setter..."); | ||
this.customerDao = customerDao; | ||
} | ||
} |