Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/guru/springframework/DiDemoApplication.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package guru.springframework;

import guru.springframework.controllers.ConstructorInjectedController;
import guru.springframework.controllers.GetterInjectedController;
import guru.springframework.controllers.SetterInjectedController;
import guru.springframework.controllers.MyController;
import guru.springframework.controllers.PropertyInjectedController;
import org.springframework.boot.SpringApplication;
Expand All @@ -19,7 +19,7 @@ public static void main(String[] args) {
controller.hello();

System.out.println(ctx.getBean(PropertyInjectedController.class).sayHello());
System.out.println(ctx.getBean(GetterInjectedController.class).sayHello());
System.out.println(ctx.getBean(SetterInjectedController.class).sayHello());
System.out.println(ctx.getBean(ConstructorInjectedController.class).sayHello());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
* Created by jt on 5/24/17.
*/
@Controller
public class GetterInjectedController {
public class SetterInjectedController {
private GreetingService greetingService;

public String sayHello(){
return greetingService.sayGreeting();
}

@Autowired
public void setGreetingService(@Qualifier("getterGreetingService") GreetingService greetingService) {
public void setGreetingService(@Qualifier("setterGreetingService") GreetingService greetingService) {
this.greetingService = greetingService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
* Created by jt on 5/24/17.
*/
@Service
public class GetterGreetingService implements GreetingService {
public class SetterGreetingService implements GreetingService {

@Override
public String sayGreeting() {
return "Hello - I was injected by the getter";
return "Hello - I was injected by the setter";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
/**
* Created by jt on 5/24/17.
*/
public class GetterInjectedControllerTest {
public class SetterInjectedControllerTest {

private GetterInjectedController getterInjectedController;
private SetterInjectedController setterInjectedController;

@Before
public void setUp() throws Exception {
this.getterInjectedController = new GetterInjectedController();
this.getterInjectedController.setGreetingService(new GreetingServiceImpl());
this.setterInjectedController = new SetterInjectedController();
this.setterInjectedController.setGreetingService(new GreetingServiceImpl());
}

@Test
public void testGreeting() throws Exception {
assertEquals(GreetingServiceImpl.HELLO_GURUS, getterInjectedController.sayHello());
assertEquals(GreetingServiceImpl.HELLO_GURUS, setterInjectedController.sayHello());
}
}