Question
I tried to fix this Error but I couldn't, help me please! Error starting ApplicationContext. To display the condition evaluation report re-run your application with
I tried to fix this Error but I couldn't, help me please!
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
[2m2023-01-28T01:37:39.204-06:00[0;39m [31mERROR[0;39m [35m50212[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.b.d.LoggingFailureAnalysisReporter [0;39m [2m:[0;39m
***************************
APPLICATION FAILED TO START
***************************
Description:
Field countryRepository in com.shahin.fleetapp.service.CountryService required a bean of type 'com.shahin.fleetapp.repositories.CountryRepository' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.shahin.fleetapp.repositories.CountryRepository' in your configuration.
===============================
Country.java
package com.shahin.fleetapp.model;
import java.util.List;
import javax.swing.plaf.nimbus.State;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class Country {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String code;
private String capital;
private String description;
private String nationality;
private String continent;
@OneToMany(mappedBy="country")
private List
}
==============================
CountryController
package com.shahin.fleetapp.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping;
import com.shahin.fleetapp.model.Country; import com.shahin.fleetapp.service.CountryService;
@Controller public class CountryController { @Autowired private CountryService countryService; //Get All Countrys @GetMapping("countries") public String findAll(Model model){ model.addAttribute("countries", countryService.findAll()); return "country"; } }
===============================
CountryService
package com.shahin.fleetapp.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;
import com.shahin.fleetapp.model.Country; import com.shahin.fleetapp.repositories.CountryRepository;
@Service public class CountryService { @Autowired private CountryRepository countryRepository; //Get All Countrys public List
}
==================================
CountryRepository
package com.shahin.fleetapp.repositories;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.shahin.fleetapp.model.Country;
@Repository
public interface CountryRepository extends JpaRepository
}
==================================
FleetappApplication
package com.shahin.fleetapp;
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) @ComponentScan({"com.shahin.fleetapp.service", "com.shahin.fleetapp.controller"}) public class FleetappApplication {
public static void main(String[] args) { SpringApplication.run(FleetappApplication.class, args); }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started