L'exception in questione è questa:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'registrazioneController' defined in file [C:\Users\Andrea\Desktop\paninoteca\target\classes\com\jabateca\paninoteca\controller\RegistrazioneController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.jabateca.paninoteca.service.implementation.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
Non mai utilizzato i bean e non so bene come utilizzarli, ma il problema sembrerebbe essere proprio essere la mancanza dei beans.
Ecco il codice incriminato: (come si può capire facilmento deve essere un controller di una calsse riegistrazione)
=================================================================
@Controller
public class RegistrazioneController {
private final UserService userService;
@Autowired
public RegistrazioneController(UserService userService) {
this.userService = userService;
}
@RequestMapping(value = "/registrazione", method = RequestMethod.GET)
public ModelAndView registration() {
ModelAndView modelAndView = new ModelAndView();
User user = new User();
modelAndView.addObject("user", user);
modelAndView.setViewName("/registrazione");
return modelAndView;
}
@RequestMapping(value = "/registrazione", method = RequestMethod.POST)
public ModelAndView createNewUser(@Validated User user, BindingResult bindingResult) {
if (userService.findByEmail(user.getEmail()).isPresent()) {
bindingResult
.rejectValue("email", "error.user",
"Email già registrata");
}
if (userService.findByUsername(user.getUsername()).isPresent()) {
bindingResult
.rejectValue("username", "error.user",
"Username già registrato");
}
ModelAndView modelAndView = new ModelAndView();
if (bindingResult.hasErrors()) {
modelAndView.setViewName("/registrazione");
} else {
userService.saveUser(user);
modelAndView.addObject("successo", "Utente registrato correttamente");
modelAndView.addObject("user", new User());
modelAndView.setViewName("/registrazione");
}
return modelAndView;
}
}
=====================================================================
Questo invece è il mio pom.xml:
========================================================================
<?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 http://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.4.3</version>
<relativePath/>
</parent>
<groupId>com.jabateca</groupId>
<artifactId>paninoteca</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>15</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-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
<version>3.3.5.RELEASE</version>
</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>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.2.4.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
=================================================================
RINGRAZIO CHIUNQUE LEGGERA'
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'registrazioneController' defined in file [C:\Users\Andrea\Desktop\paninoteca\target\classes\com\jabateca\paninoteca\controller\RegistrazioneController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.jabateca.paninoteca.service.implementation.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
Non mai utilizzato i bean e non so bene come utilizzarli, ma il problema sembrerebbe essere proprio essere la mancanza dei beans.
Ecco il codice incriminato: (come si può capire facilmento deve essere un controller di una calsse riegistrazione)
=================================================================
@Controller
public class RegistrazioneController {
private final UserService userService;
@Autowired
public RegistrazioneController(UserService userService) {
this.userService = userService;
}
@RequestMapping(value = "/registrazione", method = RequestMethod.GET)
public ModelAndView registration() {
ModelAndView modelAndView = new ModelAndView();
User user = new User();
modelAndView.addObject("user", user);
modelAndView.setViewName("/registrazione");
return modelAndView;
}
@RequestMapping(value = "/registrazione", method = RequestMethod.POST)
public ModelAndView createNewUser(@Validated User user, BindingResult bindingResult) {
if (userService.findByEmail(user.getEmail()).isPresent()) {
bindingResult
.rejectValue("email", "error.user",
"Email già registrata");
}
if (userService.findByUsername(user.getUsername()).isPresent()) {
bindingResult
.rejectValue("username", "error.user",
"Username già registrato");
}
ModelAndView modelAndView = new ModelAndView();
if (bindingResult.hasErrors()) {
modelAndView.setViewName("/registrazione");
} else {
userService.saveUser(user);
modelAndView.addObject("successo", "Utente registrato correttamente");
modelAndView.addObject("user", new User());
modelAndView.setViewName("/registrazione");
}
return modelAndView;
}
}
=====================================================================
Questo invece è il mio pom.xml:
========================================================================
<?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 http://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.4.3</version>
<relativePath/>
</parent>
<groupId>com.jabateca</groupId>
<artifactId>paninoteca</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>15</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-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
<version>3.3.5.RELEASE</version>
</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>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.2.4.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
=================================================================
RINGRAZIO CHIUNQUE LEGGERA'