0
Good colleagues. I’m starting to develop with spring, but I’m having a problem not being able to run my web application, whenever I run launches the following error message in spring:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-10-12 11:00:08.063 ERROR 13660 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field catDAO in mz.com.centropontoencontro.service.CategoriaLivroServiceImpl required a bean of type 'mz.com.centropontoencontro.dao.CategoriaLivroDAO' 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 'mz.com.centropontoencontro.dao.CategoriaLivroDAO' in your configuration.
Below I leave the classes and interfaces.
class Categorialivrodaoimpl
@Repository
public abstract class CategoriaLivroDAOImpl extends AbstractDAO<CategoriaLivro> implements CategoriaLivroDAO {
}
interface Categorialivrodao
public interface CategoriaLivroDAO {
void save(CategoriaLivro catLivro);
void update(CategoriaLivro catLivro);
void delete(Long id);
CategoriaLivro findById(Long id);
List<CategoriaLivro> findAll();
}
Interface Categorialivroservice
public interface CategoriaLivroService {
void salvar(CategoriaLivro categoriaLivro);
void editar(CategoriaLivro categoriaLivro);
void excluir(Long id);
CategoriaLivro procurarPorId(Long id);
List<CategoriaLivro> pesquisarTodos();
}
Class Categorialivroserviceimpl
@Transactional(readOnly = false) @Service public class CategoriaLivroServiceImpl implements CategoriaLivroService {
@Autowired
private CategoriaLivroDAO catDAO;
@Override
public void salvar(CategoriaLivro categoriaLivro) {
catDAO.save(categoriaLivro);
}
@Override
public void editar(CategoriaLivro categoriaLivro) {
catDAO.update(categoriaLivro);
}
@Override
public void excluir(Long id) {
catDAO.delete(id);
}
@Transactional(readOnly = true)
@Override
public CategoriaLivro procurarPorId(Long id) {
return catDAO.findById(id);
}
@Transactional(readOnly = true)
@Override
public List<CategoriaLivro> pesquisarTodos() {
return catDAO.findAll();
}
}
Execution class of the application
package mz.com.centropontoencontro;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class CentroPontoEncontroApplication {
public static void main(String[] args) {
SpringApplication.run(CentroPontoEncontroApplication.class, args);
}
}
POM.XML file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.9.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>mz.com.centropontoencontro</groupId>
<artifactId>centro-ponto-encontro</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>centro-ponto-encontro</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.springframework.boot</groupId> -->
<!-- <artifactId>spring-boot-starter-security</artifactId> -->
<!-- </dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.springframework.security</groupId> -->
<!-- <artifactId>spring-security-test</artifactId> -->
<!-- <scope>test</scope> -->
<!-- </dependency> -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
<version>0.37</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>popper.js</artifactId>
<version>1.15.0</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>font-awesome</artifactId>
<version>5.11.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
What should I do? Thank you
Post your package scan configuration (or configuration class / application)
– nullptr
sorry I’m not experienced, you’re referring to the class that is annotated with the annotation @Springbootapplication??
– Ayrton Pereira
Yes, and some more
@Configuration
if there is any– nullptr
I edited the execution class and the POM.xml file in the message itself
– Ayrton Pereira
Include the whole class, including package declaration and Imports
– nullptr
I already added in the message
– Ayrton Pereira