浏览代码

Merge pull request #5 from vvmk/readme

Update the README to suggest constructor-based DI
Git-Leon 6 年前
父节点
当前提交
cc4d312627
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 16 次插入4 次删除
  1. 16
    4
      README.md

+ 16
- 4
README.md 查看文件

108
 * Create a `PollController` class in the `controller` sub package.
108
 * Create a `PollController` class in the `controller` sub package.
109
 	* `PollController` signature should be `annotated` with `@RestController`
109
 	* `PollController` signature should be `annotated` with `@RestController`
110
 
110
 
111
-* `PollController` has a `pollRepository` instance variable of type `PollRepository`
112
-	* `pollRepository` should be `annotated` with `@Inject`
111
+* `PollController` has a `pollRepository` instance variable of type `PollRepository`  
112
+
113
+* Create a constructor that accepts a `PollRepository` argument and assigns its value to the `pollRepository` member variable.  
114
+	* Mark the constructor with the `@Autowired` annotation.
113
 
115
 
114
 
116
 
115
 ### Part 3.1.1 - Create `GET` request method
117
 ### Part 3.1.1 - Create `GET` request method
273
 ```java
275
 ```java
274
 @RestController
276
 @RestController
275
 public class VoteController {
277
 public class VoteController {
276
-    @Inject
278
+
277
     private VoteRepository voteRepository;
279
     private VoteRepository voteRepository;
280
+    
281
+    @Autowired
282
+    public VoteController(VoteRepository voteRepository) {
283
+    	this.voteRepository = voteRepository;
284
+    }
278
 
285
 
279
     @RequestMapping(value = "/polls/{pollId}/votes", method = RequestMethod.POST)
286
     @RequestMapping(value = "/polls/{pollId}/votes", method = RequestMethod.POST)
280
     public ResponseEntity<?> createVote(@PathVariable Long pollId, @RequestBody Vote
287
     public ResponseEntity<?> createVote(@PathVariable Long pollId, @RequestBody Vote
414
 ```java
421
 ```java
415
 @RestController
422
 @RestController
416
 public class ComputeResultController {
423
 public class ComputeResultController {
417
-    @Inject
424
+    
418
     private VoteRepository voteRepository;
425
     private VoteRepository voteRepository;
426
+    
427
+    @Autowired
428
+    public ComputeResultController(VoteRepository voteRepository) {
429
+    	this.voteRepository = voteRepository;
430
+    }
419
 
431
 
420
     @RequestMapping(value = "/computeresult", method = RequestMethod.GET)
432
     @RequestMapping(value = "/computeresult", method = RequestMethod.GET)
421
     public ResponseEntity<?> computeResult(@RequestParam Long pollId) {
433
     public ResponseEntity<?> computeResult(@RequestParam Long pollId) {