I need some help. I'm using Java with Springboot and I'm working on a project that essentially displays info from a database (book titles, authors, language, and so on) onto a webpage, and navigating the website allows me to make changes to the database like edit an entry, create a new entry, show an entry, or delete an entry.
It worked just fine till I had to shut down my computer, and then when I returned and tried to run that project again, it gives me the error below along with a lot of other text. I restarted the server, ran it in debug mode, nothing seemed to work. It's almost as if I broke some kind of connection that was there before, or I deleted something that I wasn't supposed to have deleted. I just can't figure out what it could be. I was hoping anyone can tell me what I might've done wrong so I can reverse it and have it up and running again.
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
[2m2020-03-16 23:06:05.766[0;39m [31mERROR[0;39m [35m49106[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mo.s.boot.SpringApplication [0;39m [2m:[0;39m Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Note that I did not learn about "hibernate" directly, and only heard of this term when I saw this error and tried Googling for an answer. I tried some of the other solutions mentioned on stackoverflow for people with a very similar problem but it doesn't work for me (namely, adding a specific dependency regarding hibernate, but I don't remember the details of it right now off the top of my head).
Below is some of the code I used for the various packages:
Property
spring.datasource.url=jdbc:mysql://localhost:3306/book-schema2
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
spring.mvc.view.prefix=/WEB-INF/
In the 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.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.blank.mvc2</groupId>
<artifactId>mvc2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>mvc2</name>
<description>mvc2</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-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>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
In the models package: import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;
import javax.validation.constraints.Min;
import javax.validation.constraints.Size;
import org.springframework.format.annotation.DateTimeFormat;
@Entity
@Table(name="books2")
public class Book {
In the repositories package:
import java.util.List;
import java.util.Optional;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface BookRepository extends CrudRepository<Book, Long> {
In the Services package:
import java.util.List;
import java.util.Optional;
import org.springframework.stereotype.Service;
@Service
public class BookService {
In the controllers package:
import java.util.List;
import javax.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class BooksController {
Mind you, I did this project already, and was doing it again for practice, and both projects worked before, but now neither project works. It was working fine till I rebooted my computer (no updates on the computer itself during that time). If you want more info, let me know. I just need help with figuring this out right now as it makes no sense to me why it would work one minute and then by simply turning the computer on/off it doesn't work the next minute.