3

I'm new into SpringMVC and got stuck here. I created a Spring Boot application through Spring Initializr and then created HomeController, connected it with index.jsp. It was working fine but when I added SearchController, connected with search.jsp, it dosen't work now. Before adding SearcController, the application was running fine but then it says:

Failed to execute goal ...plugin:2.4.0:run (default-cli) on project hplus : Application finished with exit code: 1

Update: after doing some searches I found out that my database's server was not running and after running that, and running my application as Test, I got this error.

Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set .

Full Error!
Test set:HplusappApplicationTests
<<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: 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]
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

.

pom.xml file ->
<code>
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 
  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.4.0</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>spring-example</groupId>
<artifactId>myapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>myapp</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-web</artifactId>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
    </build>

</project>

application.properties ->

spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/hplus
spring.datasource.username=root
spring.datasource.password=root
Wais Shuja
  • 113
  • 1
  • 9
  • 1
    Without knowing wy it fails (i.e. the full error or test failure) it is impossible to answer this question. – M. Deinum Nov 19 '20 at 06:18
  • @M. Deinum I have no idea how to find the whole and error and that's what I'm looking for. But the console says: **Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.0:run (default-cli) on project myapp: Application finished with exit code: 1** – Wais Shuja Nov 19 '20 at 07:31
  • Run with debug information or just run things in your IDE. – M. Deinum Nov 19 '20 at 07:36
  • Thanks for your guidance, I could debug and find the full error, there I posted it on top. – Wais Shuja Nov 19 '20 at 08:06
  • That isn't the full error. That is indicating you are running without a proper task. – M. Deinum Nov 19 '20 at 08:14
  • I thin now I found the error, just updated the post – Wais Shuja Nov 19 '20 at 10:36

4 Answers4

1

Solution After searching for more than two days, I found out it's the timeZone problem.

I edited application.properties, line two ->

spring.datasource.url=jdbc:mysql://localhost:3306/hplus?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false

https://stackoverflow.com/a/56537473/14623694

It solved the issue.

Wais Shuja
  • 113
  • 1
  • 9
0
[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]

It clearly says that you entered a wrong mvn command. What is the command you executed? We generally run mvn clean install to build an application. Here is a list of Maven commands that might help you.

sas
  • 512
  • 2
  • 8
  • **'hibernate.dialect' not set** You have to add `spring.jpa.properties.hibernate.dialect` in properties it seems. – sas Nov 19 '20 at 11:08
0

You need to specify the MySQL dialect Hibernate should use :

put this in application.properties:

spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
BlueSoft
  • 36
  • 3
0

There seems to be error's when defining the bean and also your pom file, have you tried running a clean instal, with the

mvn clean instal

command? If that still doesn't work try to look at your pom and application.properties file is there still some mixed versions? If that still doesn't work try deleting your .m2 file and run the mvn clean install once again.