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
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package guru.springframework.spring6di;

import guru.springframework.spring6di.controllers.MyController;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Spring6DiApplication {

public static void main(String[] args) {
SpringApplication.run(Spring6DiApplication.class, args);
final var context = SpringApplication.run(Spring6DiApplication.class, args);

System.out.println("Hello from the Main");

final var myController = context.getBean(MyController.class);

System.out.println(myController.sayHello());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package guru.springframework.spring6di.controllers;

import guru.springframework.spring6di.services.GreetingsService;
import guru.springframework.spring6di.services.impl.GreetingsServiceImpl;
import org.springframework.stereotype.Controller;

@Controller
public class MyController {

private final GreetingsService greetingsService;

public MyController() {
this.greetingsService = new GreetingsServiceImpl() {};
}

public String sayHello() {
System.out.println("I'm the MyController!!");

return this.greetingsService.sayHello();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package guru.springframework.spring6di.services;

public interface GreetingsService {

String sayHello();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package guru.springframework.spring6di.services.impl;

import guru.springframework.spring6di.services.GreetingsService;

public class GreetingsServiceImpl implements GreetingsService {
@Override
public String sayHello() {
return "Hello from the Greetings Service";
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
package guru.springframework.spring6di;

import guru.springframework.spring6di.controllers.MyController;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;

@SpringBootTest
class Spring6DiApplicationTests {

@Autowired
private ApplicationContext context;

@Autowired
private MyController myController;

@Test
void myControllerAutowired() {
System.out.println(this.myController.sayHello());
}

@Test
void applicationContextAutowired() {
final var controller = this.context.getBean(MyController.class);
System.out.println(controller.sayHello());
}

@Test
void contextLoads() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package guru.springframework.spring6di.controllers;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class MyControllerTest {

@Test
void sayHello() {
final var myController = new MyController();

System.out.println(myController.sayHello());
}
}