1

My projects works great in eclipse, but when creating a jar and installing it works and I can open my web page but doing some queries it doesnt, but this only happens in my jar not in eclipse so I guess the problem has to do something with dependencies. The thing is that I have tried everything on stack. tried this following solutions:

Failed to process import candidates for configuration class

How can I create an executable JAR with dependencies using Maven?

How to make a “fat jar” of a Maven project? [duplicate]

64. Spring Boot Maven plugin

But its always the same some queries wont execute. I dont really know what im doing wrong here, now I went back to where I started and my POM looks like:

<?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>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.RELEASE</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <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-starter-mail</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-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/net.sourceforge.nekohtml/nekohtml -->
        <dependency>
            <groupId>net.sourceforge.nekohtml</groupId>
            <artifactId>nekohtml</artifactId>
            <version>1.9.21</version><!--$NO-MVN-MAN-VER$-->
        </dependency>

        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity4</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.3.2</version>
        </dependency>     
    </dependencies>

    <build>
        <plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <fork>true</fork>
            <mainClass>com.example.DemoApplication</mainClass>
        </configuration>
        <executions>
              <execution>
                <goals>
                  <goal>repackage</goal>
                </goals>
              </execution>
            </executions>
    </plugin>
</plugins>
    </build>
</project>

"EDIT:this is my properties file"

# ===============================
# = Conexion con la base de datos
# ===============================
spring.datasource.url=jdbc:mysql://*****/vudaspring?useSSL=false
spring.datasource.username=*******
spring.datasource.password =********
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery=SELECT 1


# ===============================
# = JPA / HIBERNATE
# ===============================
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
# ===============================
# = Thymeleaf configuracion
# ===============================
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.cache=false
# ===============================
# = Multipart Files
# ===============================
spring.http.multipart.max-file-size=10MB
spring.http.multipart.max-request-size=10MB

# ==============================================================
# = Spring Security / Authentication Queries 
# ==============================================================
spring.queries.users-query=select email, password, active from user where email=?
spring.queries.roles-query=select u.email, r.role from user u inner join user_role ur on(u.user_id=ur.user_id) inner join role r on(ur.role_id=r.role_id) where u.email=?
spring.queries.pais-query=SELECT * FROM pais
spring.queries.tipousuario-query=SELECT * FROM tipoUsuario

# ==============================================================
# = Propiedades del Email
# ==============================================================
spring.mail.host= smtp.gmail.com
spring.mail.username= ventanillaunicada@gmail.com
spring.mail.password= *******
spring.mail.port= 587
spring.mail.properties.mail.smtp.starttls.enable = true

"EDIT:this is my WebMvcConfig"

package com.example.configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ErrorAttributes;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.example.controller.VudaErrorController;

@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Autowired
    private ErrorAttributes errorAttributes;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.
        addResourceHandler("/files/**")
        .addResourceLocations("file:../imagenes/");
    }

    @Bean
    public BCryptPasswordEncoder passwordEncoder() {
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        return bCryptPasswordEncoder;
    }

    @Bean
    public VudaErrorController vudaErrorController() {return new VudaErrorController(errorAttributes);}

}
Teler
  • 477
  • 6
  • 15
  • What's wrong with your queries? What exception(s) are you getting? – Roddy of the Frozen Peas Oct 02 '18 at 22:22
  • @RoddyoftheFrozenPeas Thanks for the reply, the exception is saying that the query returns null, but this cant be possible because only happens in the jar and not the eclipse project (the database is the same) – Teler Oct 02 '18 at 22:28
  • How do you know that it is connecting properly with the database? The problem is more likely to be in your properties files or configurations -- the pom looks fine, even if that version of spring-boot is nearly 2 years old. – Roddy of the Frozen Peas Oct 02 '18 at 22:42
  • @RoddyoftheFrozenPeas Im working with the project and the database in eclipse and everything works great, the problem starts when I generate a .jar, if I dont generate a jar the project works as expected, thats why I believe it has something to do with the .jar and not my end because if not it wouldn't work even without the .jar – Teler Oct 02 '18 at 22:48
  • @RoddyoftheFrozenPeas I explained all that in this post: https://stackoverflow.com/questions/52600051/i-get-errors-when-executing-my-spring-boot-jar-with-maven – Teler Oct 02 '18 at 22:49
  • Neither of these questions has your properties/configuration in it. Eclipse does a lot for you, like make sure stuff is on your classpath. – Roddy of the Frozen Peas Oct 02 '18 at 23:04
  • @RoddyoftheFrozenPeas "you are right, added the properties,thanks for the help" – Teler Oct 02 '18 at 23:43
  • spring-boot-maven-plugin should be what you need. It works fine in our large amount of services cluster. BTW, what's your problem? In other words, which phase does your application fails at? – Horsing Oct 03 '18 at 03:04
  • @GeminiKeith Im already using the spring-boot-maven-plugin in my POM. It fails when trying to get data from a database and the query uses an inner join, I can properly insert data and select but not when its an inner join. My web page does work in eclipse properly but as soon as I create a jar it presents the problems that I explained, even tho nothing changes since Im using the same database url. – Teler Oct 03 '18 at 05:08
  • @RoddyoftheFrozenPeas I changed my Query from nativeQuery to JQL and its now working, any idea why? maybe some dependency problem? I dont really want to change every query if I can avoid that. – Teler Oct 03 '18 at 23:28

0 Answers0