JavaRush /Java Blog /Random EN /Spring is not scary, learning to solve problems
Павел
Level 11

Spring is not scary, learning to solve problems

Published in the Random EN group
CONTENTS OF THE CYCLE OF ARTICLES Today's article will be the quintessence of altruism (freebie - in one word). I have developed one very useful library for myself. She solves any problem. Web service? Please! Chatbot? Convolutional Neural Network? No problem! I'm not sorry to share it with you: "en.java.rush.chuck-norris-1.0.jar" It is named after Chuck Norris for his ability to solve problems quickly. Let me show you how to use it. Download the file, save it somewhere where it can be easily found later. Now let's quickly create an empty spring-boot project , connect Lombok. In the project, we will create the utils packageand the already familiar class InitiateUtils implement CommandLineRunner. Load the library into the projectas follows (for new versions of Intellij IDEA, the “+” is located at the bottom left, above the Dependencies storage format inscription). The library now appears in the project's External Libraries drop-down list (you may need to restart the project afterwards). It's time to inject our Chuck into the InitiateUtils class and implement a method there to solve all the problems. Let's write our problem in the method parameter: "I want to write a super-duper project so that they would immediately take me to Google!".
package ru.java.rush.utils;

import lombok.RequiredArgsConstructor;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Service;
import ru.java.rush.ChuckNorris;

@Service
@RequiredArgsConstructor
public class InitiateUtils implements CommandLineRunner {

    private final ChuckNorris chuckNorris;

    @Override
    public void run(String... args) throws Exception {
        //метод для решения всех проблем
        chuckNorris.SolutionToAllProblems("Want написать супер-пупер проект, чтобы меня сразу взяли в Гугл!");
    }
}
Now this guy in the hat will start to work wonders. We start the project. Spring is not scary, learning to solve problems - 1Chuck Norris and Dmitry Nagiev meet once in a public bath ... HOW !!?? WHAT!?? Error? Yes, and in a foreign language! It can't be, because we did everything as it is written above! Oh my God! This means we won’t write a super-duper project, and we won’t be taken to Google, and we won’t get to Hollywood and see Mr. Norris there!😭😭😭 So, set aside! Chuck Norris never cries from mistakes, it's mistakes that cry from him! Let's figure it out, that's actually the whole error:
***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in ru.java.rush.utils.InitiateUtils required a bean of type 'ru.java.rush.ChuckNorris' that could not be found.


Action:

Consider defining a bean of type 'ru.java.rush.ChuckNorris' in your configuration.
I am not strong in English, but it says something like this: That the application did not start because the constructor parameter (By the way, do you know what constructor we are talking about? I didn’t see any constructors in the code) InitiateUtils requires a ChuckNorris type bean, which was not found . Then he offers us a solution: Try to define the ChuckNorris Bean in your configuration. In other words, you need to configure the bean! Those who read the links, which I left earlier, breathed a sigh of relief, they know what and how to do. Well, those who have not read it yet, probably read it now. Do you think ChuckNorris is in context now or not? I think you can go further without me: Configure the ChuckNorris bean and call the method to solve all problems. In the meantime, I'll go and watch a couple of episodes of Cool Walker ...
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION