diff --git a/Drafts/Weather2/Weather2.iml b/Drafts/Weather2/Weather2.iml index 78b2cc5..f76df2b 100644 --- a/Drafts/Weather2/Weather2.iml +++ b/Drafts/Weather2/Weather2.iml @@ -1,2 +1,11 @@ - \ No newline at end of file + + + + + + + + + + \ No newline at end of file diff --git a/GuessNumber/pom.xml b/GuessNumber/pom.xml new file mode 100644 index 0000000..5324bcf --- /dev/null +++ b/GuessNumber/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + + groupId + GuessNumber + 1.0-SNAPSHOT + + + + + org.springframework + spring-context + 5.2.8.RELEASE + + + + + + \ No newline at end of file diff --git a/GuessNumber/src/GuessSource.java b/GuessNumber/src/GuessSource.java deleted file mode 100644 index bc6c35b..0000000 --- a/GuessNumber/src/GuessSource.java +++ /dev/null @@ -1,3 +0,0 @@ -public interface GuessSource { - public int guess(); -} diff --git a/GuessNumber/src/Main.java b/GuessNumber/src/Main.java deleted file mode 100644 index be40a08..0000000 --- a/GuessNumber/src/Main.java +++ /dev/null @@ -1,20 +0,0 @@ -public class Main { - - public static void main(String[] args) { - - KeyboardGuess source = new KeyboardGuess(); - ConsoleOutput output = new ConsoleOutput(); - int secretNumber = 15; - int attemptsCount = 3; - - GuessNumberGame game = new GuessNumberGame( - secretNumber, - attemptsCount, - source, - output); - - game.play(); - } - - -} diff --git a/GuessNumber/src/main/java/ApplicationConfig.java b/GuessNumber/src/main/java/ApplicationConfig.java new file mode 100644 index 0000000..304d5ab --- /dev/null +++ b/GuessNumber/src/main/java/ApplicationConfig.java @@ -0,0 +1,25 @@ +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan +public class ApplicationConfig { + + @Bean + public KeyboardGuess getkeyboardGuess() { + return new KeyboardGuess(); + } + + @Bean + public ConsoleOutput getconsoleOutput() { + return new ConsoleOutput(); + } + + @Bean + public GuessNumberGame getguessNumberGame(KeyboardGuess keyboardGuess, ConsoleOutput consoleOutput) { + return new GuessNumberGame(15, 3, keyboardGuess, consoleOutput); + } + + +} diff --git a/GuessNumber/src/ConsoleOutput.java b/GuessNumber/src/main/java/ConsoleOutput.java similarity index 71% rename from GuessNumber/src/ConsoleOutput.java rename to GuessNumber/src/main/java/ConsoleOutput.java index 79d3cf1..705aeca 100644 --- a/GuessNumber/src/ConsoleOutput.java +++ b/GuessNumber/src/main/java/ConsoleOutput.java @@ -1,3 +1,6 @@ +import org.springframework.stereotype.Component; + +@Component public class ConsoleOutput implements ResultOutput { @Override diff --git a/GuessNumber/src/GuessNumberGame.java b/GuessNumber/src/main/java/GuessNumberGame.java similarity index 99% rename from GuessNumber/src/GuessNumberGame.java rename to GuessNumber/src/main/java/GuessNumberGame.java index 149d6f0..76c9723 100644 --- a/GuessNumber/src/GuessNumberGame.java +++ b/GuessNumber/src/main/java/GuessNumberGame.java @@ -1,4 +1,3 @@ - public class GuessNumberGame { private int secretNumber; diff --git a/GuessNumber/src/main/java/GuessSource.java b/GuessNumber/src/main/java/GuessSource.java new file mode 100644 index 0000000..76814f2 --- /dev/null +++ b/GuessNumber/src/main/java/GuessSource.java @@ -0,0 +1,6 @@ +import org.springframework.stereotype.Component; + +@Component +public interface GuessSource { + public int guess(); +} diff --git a/GuessNumber/src/KeyboardGuess.java b/GuessNumber/src/main/java/KeyboardGuess.java similarity index 77% rename from GuessNumber/src/KeyboardGuess.java rename to GuessNumber/src/main/java/KeyboardGuess.java index 3482a5d..f209a81 100644 --- a/GuessNumber/src/KeyboardGuess.java +++ b/GuessNumber/src/main/java/KeyboardGuess.java @@ -1,5 +1,8 @@ +import org.springframework.stereotype.Component; + import java.util.Scanner; +@Component public class KeyboardGuess implements GuessSource { Scanner scanner = new Scanner(System.in); @Override diff --git a/GuessNumber/src/main/java/Main.java b/GuessNumber/src/main/java/Main.java new file mode 100644 index 0000000..e18690a --- /dev/null +++ b/GuessNumber/src/main/java/Main.java @@ -0,0 +1,35 @@ +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.ProxyAsyncConfiguration; + +public class Main { +// авг 30, 2020 1:29:53 AM org.springframework.context.support.AbstractApplicationContext refresh +// WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.annotation.internalAsyncAnnotationProcessor' defined in class path resource [org/springframework/scheduling/annotation/ProxyAsyncConfiguration .class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor]: Factory method 'asyncAdvisor' threw exception; nested exception is java.lang.IllegalArgumentException: @EnableAsync +// annotation metadata was not injected +// Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.annotation.internalAsyncAnnotationProcessor' defined in class path resource [org/springframework/scheduling/annotation/ProxyAsyncConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor]: Factory method 'asyncAdvisor' threw exception; nested exception is java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected + + + public static void main(String[] args) { +// ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); + ApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfig.class); + +// KeyboardGuess source = new KeyboardGuess(); +// ConsoleOutput output = new ConsoleOutput(); +// int secretNumber = 15; +// int attemptsCount = 3; +// +// GuessNumberGame game = new GuessNumberGame( +// secretNumber, +// attemptsCount, +// source, +// output); + GuessNumberGame game = context.getBean("guessNumberGame", GuessNumberGame.class); + + game.play(); + } + + +} diff --git a/GuessNumber/src/ResultOutput.java b/GuessNumber/src/main/java/ResultOutput.java similarity index 54% rename from GuessNumber/src/ResultOutput.java rename to GuessNumber/src/main/java/ResultOutput.java index 4b9d0c7..ea5ed87 100644 --- a/GuessNumber/src/ResultOutput.java +++ b/GuessNumber/src/main/java/ResultOutput.java @@ -1,3 +1,6 @@ +import org.springframework.stereotype.Component; + +@Component public interface ResultOutput { public void output(String result); } diff --git a/GuessNumber/src/main/resources/beans.xml b/GuessNumber/src/main/resources/beans.xml new file mode 100644 index 0000000..7083162 --- /dev/null +++ b/GuessNumber/src/main/resources/beans.xml @@ -0,0 +1,13 @@ + + + + + + + \ No newline at end of file