Commit c07bc382 by Patryk Czarnik

Tworzenie Komponentu w @Configuration / @Bean

parent 1a38f651
package com.example.demo.wstrzykiwanie;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FabrykaKomponentow {
{ System.out.println("FabrykaKomponentow init"); }
@Bean
public Komponent dajKomponent() {
System.out.println("Zaraz utworzę Komponent w klasie FabrykaKomponentow");
return new Komponent();
}
}
...@@ -2,9 +2,6 @@ package com.example.demo.wstrzykiwanie; ...@@ -2,9 +2,6 @@ package com.example.demo.wstrzykiwanie;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import org.springframework.stereotype.Component;
@Component
public class Komponent { public class Komponent {
{ System.out.println("Komponent init"); } { System.out.println("Komponent init"); }
......
...@@ -2,7 +2,7 @@ package com.example.demo.wstrzykiwanie; ...@@ -2,7 +2,7 @@ package com.example.demo.wstrzykiwanie;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@Repository @Repository // na podobnych zasadach: @Component, @Service, @Repository - tworzony jest jeden obiekt "singleton"
public class Repo { public class Repo {
{ System.out.println("Repo init"); } { System.out.println("Repo init"); }
......
package com.example.demo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class Pc19SpringTechnicznieApplicationTests {
@Test
void contextLoads() {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment