JavaFX Exception in Application start method when executed with Spring Boot - java

I have created a simple javaFX program and i added spring boot to javaFX by making the project a maven project. Before adding spring boot i got no error and the application worked fine.
I have provided the complete code below
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.2.6.RELEASE</version>
</parent>
<groupId>groupId</groupId>
<artifactId>RMI-DesktopClient</artifactId>
<version>1.0-SNAPSHOT</version>
<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</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>
AlarmsystemApplication.java
#Configuration
#SpringBootApplication
public class AlarmSystemApplication extends Application {
private ConfigurableApplicationContext applicationContext;
#Override
public void init() throws Exception {
this.applicationContext = SpringApplication.run(AlarmSystemApplication.class);
}
#Override
public void stop() throws Exception {
applicationContext.close();
}
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage stage) throws Exception {
Login.loadView(stage);
}
}
Login.java
public class Login {
public static void loadView(Stage stage) {
try {
Parent view = FXMLLoader.load(Login.class.getResource("../../../../../resources/com.ui.views/Login.fxml"));
stage.setScene(new Scene(view));
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Login.fxml
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.alarmsystem.ui.views.Login">
<children>
<Label layoutX="137.0" layoutY="157.0" text="Hello JavaFX">
<font>
<Font size="59.0" />
</font>
</Label>
</children>
</AnchorPane>
The error that i get
Exception in Application start method
2020-04-23 22:33:12.134 INFO 7228 --- [lication Thread] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2020-04-23 22:33:12.136 INFO 7228 --- [lication Thread] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2020-04-23 22:33:12.139 INFO 7228 --- [lication Thread] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at com.alarmsystem.ui.views.Login.loadView(Login.java:16)
at com.alarmsystem.ui.AlarmSystemApplication.start(AlarmSystemApplication.java:34)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
... 1 more
Exception running application com.alarmsystem.ui.AlarmSystemApplication
Process finished with exit code 1
The file structure
The resources path

I'm not sure this is Spring related; the resource name you use for your FXML is not a valid resource name (and the stack trace indicates that not being able to find the FXML file is the issue).
Specifically, resource names cannot have . in them, so .. and com.ui.views are both invalid.
So there are two problems here: one is that the resources name doesn't work with "parent directories" specified in it, and the other is that you have created a folder (not a package) under resources with illegal . characters in it. Also note that resources is a source folder, and is not available at runtime.
So, first, create a package under resources called com.ui.views and place the FMXL in there. I don't use IntelliJ, so I'm not sure if there is an option to do this, but if not you can create a folder com, a subfolder of it called ui, and a subfolder of that called views, and place the FXML file in views.
Then the correct resource name for the FXML, assuming you are using Maven defaults for your build, is
Parent view = FXMLLoader.load(Login.class.getResource("/com/ui/views/Login.fxml"));
If you restructure slightly so that the FXML file and Login class are in the same package (i.e. you make a com.alarmsystem.ui.views package under resources), then you can just do
Parent view = FXMLLoader.load(Login.class.getResource("Login.fxml"));
If you need to troubleshoot further, you can see where the resources were deployed (so where they are found at runtime), by looking in the target/classes folder.

Related

Problem with hibernate + maven + mysql server configuration

I have a problem with connecting to mysql database that I have created on google cloud. I easily connected mysql workbench to the database but I have a problem with configuring hibernate in my maven project. Here is the error log that shows when I want to run my application:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.NoClassDefFoundError: java/sql/SQLException
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:468)
at org.jboss.logging#3.4.2.Final/org.jboss.logging.Logger.doGetMessageLogger(Logger.java:2562)
at org.jboss.logging#3.4.2.Final/org.jboss.logging.Logger.getMessageLogger(Logger.java:2530)
at org.jboss.logging#3.4.2.Final/org.jboss.logging.Logger.getMessageLogger(Logger.java:2516)
at org.hibernate.orm.core#5.5.7.Final/org.hibernate.internal.HEMLogging.messageLogger(HEMLogging.java:28)
at org.hibernate.orm.core#5.5.7.Final/org.hibernate.internal.HEMLogging.messageLogger(HEMLogging.java:24)
at org.hibernate.orm.core#5.5.7.Final/org.hibernate.jpa.boot.internal.PersistenceXmlParser.<clinit>(PersistenceXmlParser.java:54)
at org.hibernate.orm.core#5.5.7.Final/org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:81)
at org.hibernate.orm.core#5.5.7.Final/org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:61)
at org.hibernate.orm.core#5.5.7.Final/org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:50)
at java.persistence#2.2/javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at java.persistence#2.2/javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at SlidingPuzzle/controllers.Main.start(Main.java:36)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Caused by: java.lang.ClassNotFoundException: java.sql.SQLException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 23 more
Exception running application controllers.Main
Here is my pom 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>controllers</groupId>
<artifactId>SlidingPuzzle</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<javafx.version>13</javafx.version>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.26</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.5.7.Final</version>
</dependency>
</dependencies>
</project>
My module-info file:
module SlidingPuzzle {
requires javafx.controls;
requires javafx.fxml;
requires java.persistence;
opens controllers to javafx.fxml;
exports controllers;
}
and my main file where i try too initialize an EntityManger and EntityManagerFactory:
package controllers;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Screen;
import javafx.stage.Stage;
import models.database.User;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
public class Main extends Application {
private static Stage stage;
public static Stage getStage(){
return stage;
}
public static void setStage(Stage stage){
Main.stage = stage;
}
#Override
public void start(Stage primaryStage) throws Exception{
setStage(primaryStage);
FXMLLoader loader = new FXMLLoader();
loader.setLocation(this.getClass().getResource("/views/main.fxml"));
AnchorPane anchorPane = loader.load();
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("manager1");
EntityManager entityManager = entityManagerFactory.createEntityManager();
EntityTransaction entityTransaction=entityManager.getTransaction();
Scene scene = new Scene(anchorPane,1024,600);
primaryStage.setScene(scene);
primaryStage.setMaximized(true);
primaryStage.setTitle("Sliding Puzzle");
primaryStage.setMinHeight(600);
primaryStage.setMinWidth(1024);
primaryStage.setResizable(true);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
I know that the error leads me to the moment where I try to create an EntityMAnagerFactroy but I don't know why does is show me that. Thanks for any help or a push in the right direction.
You need requires java.sql; in the module-info.java file in order to make use of the features of the java.sql module.
For more information, see a java 9 module tutorial.
There are likely other required modules that you will need to add to your module-info specification in order to get your application to work.

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication.Tried all the solution but still not

Console Error
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
at com.ayush.JavaApi.main(JavaApi.java:10)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
pom.xml
<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.ayush</groupId>
<artifactId>JavaCourse</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
JavaClass with Main Method
package com.ayush;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class JavaApi {
public static void main(String[] args) {
SpringApplication.run(JavaApi.class,args);
}
}
I am running this program as java application but it is giving me error. i have try all the solution and also provided in the stackoverflow which is updating the maven but it is not working and still giving me the error.
thanks for the help in advance.
I've copied all your files to Intellij but it had no issue with your file.
Maybe hierarchical structure of your project (class JavaApi should be in JavaCourse package) or IDE setting (clean/rebuild, reimport pom) is wrong.
For beginning with Spring boot. You can generate project from https://start.spring.io/
I deleted the Project and created it again .It worked for me .Thanks everyone for the help

Lifecycle exception when deploying example spring boot app

I am trying to understand the basic steps of how to deploy a spring boot application. However, despite the fact that I do everything correctly, I can't deploy it on a tomcat server. The tomcat successfuly extracts my war archive but it gives the folloving below error:
11-Dec-2016 16:49:31.975 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/springrest]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.webresources.StandardRoot#5a0050e9]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4842)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4974)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 10 more
Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [org.apache.catalina.webresources.JarResourceSet#57a81b37]
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:112)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
at org.apache.catalina.webresources.StandardRoot.startInternal(StandardRoot.java:708)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 13 more
Caused by: java.lang.IllegalArgumentException: java.util.zip.ZipException: invalid END header (bad central directory offset)
at org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.initInternal(AbstractSingleArchiveResourceSet.java:113)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)
... 16 more
Caused by: java.util.zip.ZipException: invalid END header (bad central directory offset)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:219)
at java.util.zip.ZipFile.<init>(ZipFile.java:149)
at java.util.jar.JarFile.<init>(JarFile.java:166)
at java.util.jar.JarFile.<init>(JarFile.java:103)
at org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.initInternal(AbstractSingleArchiveResourceSet.java:110)
... 17 more
11-Dec-2016 16:49:31.976 SEVERE [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive /home/bora/Desktop/apache-tomcat-8.5.9/webapps/springrest.war
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/springrest]]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:756)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
I think the error is caused by a ZipException. But I don't understand why. I have followed this and this guides as exactly as it written, but ...
Here is more files, maybe it will be useful:
pom.xml:
<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.bora.test</groupId>
<artifactId>springrest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</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>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<!-- <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> -->
<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
</project>
And my Application class:
package com.bora.rest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
#Configuration
#ComponentScan
#EnableAutoConfiguration
public class Application extends SpringBootServletInitializer {
private static Class<Application> applicationClass = Application.class;
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
// TODO Auto-generated method stub
return builder.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
class GreetingController {
#RequestMapping("/")
String hello() {
return "Hello World";
}
}
I compile and package my maven project by givin mvn clean package and coppy the .war file into my tomcat's webapps folder. Restart the tomcat, it extracts but the above error occurs. I have been searching for solution for about 2 hours, but ...
My tomcat version is 8.5.9. I am using Ubuntu 16.04. Environment variables:
$CATALINA_BASE: /home/bora/Desktop/apache-tomcat-8.5.9
$CATALINA_HOME: /home/bora/Desktop/apache-tomcat-8.5.9
$CATALINA_TMPDIR: /home/bora/Desktop/apache-tomcat-8.5.9/temp
$JRE_HOME: /home/bora/Applications/jdk1.8.0_111
$CLASSPATH: /home/bora/Desktop/apache-tomcat-8.5.9/bin/bootstrap.jar:/home/bora/Desktop/apache-tomcat-8.5.9/bin/tomcat-juli.jar
I have strong knowledge about java language, I develop android applications. However, I am totally stranger to Java EE technologies. If someone finds an answer, could you please tell me the answer like you telling a child?
Thank you very much.
Spring-Boot ist using Tomcat 7 as default. This should be the reason why you get an exception. If u want to use Tomcat 8.5.9 u have to set the Version in your pom.xml:
<properties>
<tomcat.version>8.5.9</tomcat.version>
</properties>
EDIT
Use the spring-boot-maven-plugin for building the app. So you cant be sure your app is builded correctly.
EDIT 2
Just annotate your class with #SpringBootApplication this is enough. your Dont need the other ones.
EDIT 3
After compiling your code with my mentioned changes it worket fine. So the issue must be your config. Clear your local maven-repository and redownload the libaries. That should work.
It seems the version conflict, please check compiled version and JVM of Tomcat version are same.
Pls check JAVA_HOME
Check the Tomcat version to build. Follow the link: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-servlet-containers.html
Check the Java version to build: http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-build-systems.html
Hope this help.

Spring Boot Starter-Web tries to connect to Mongo at startup

I am experiencing some problems using Spring Boot and MongoDB external driver. I can't use the project Spring Data MongoDB, because I need to use the ufficial async driver given by Mongo. However, I need to use Spring Boot, because the module I am developing is part of a bigger project using this library.
Here is my 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>tx-view</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- omissis -->
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-async</artifactId>
<version>${mongodb.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
In detail, I am using Spring Boot 1.4.1 and Mongo Async Driver 3.2.2.
Here is my application.
#SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
public class TxViewApplication {
public static void main(String[] args) {
SpringApplication.run(TxViewApplication.class, args);
}
#Value("${mongo.uri}")
private String mongoUri;
#Bean
public MongoClient mongoClient() {
return MongoClients.create(mongoUri);
}
}
It follows the only (empty) test I have at the moment.
#SpringBootTest
#RunWith(SpringRunner.class)
public class ApplicationTest {
#Test
public void loadContext() throws Exception {}
}
I have no other code in this project. When I run the test, I have the following error:
2016-11-22 15:43:58.597 INFO 4572 --- [null'}-db:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server db:27017
com.mongodb.MongoException: java.io.IOException: Il computer remoto ha rifiutato la connessione di rete.
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:125) ~[mongodb-driver-core-3.2.2.jar:na]
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:128) ~[mongodb-driver-core-3.2.2.jar:na]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_101]
Caused by: java.io.IOException: Il computer remoto ha rifiutato la connessione di rete.
at sun.nio.ch.Iocp.translateErrorToIOException(Iocp.java:309) ~[na:1.8.0_101]
at sun.nio.ch.Iocp.access$700(Iocp.java:46) ~[na:1.8.0_101]
at sun.nio.ch.Iocp$EventHandlerTask.run(Iocp.java:399) ~[na:1.8.0_101]
at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112) ~[na:1.8.0_101]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_101]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_101]
... 1 common frames omitted
As you can see, I have properly inserted the exclude clause in the SpringBootApplication annotation in order to stop Spring Boot to try handle its own the connection to Mongo, as suggested in Mongo tries to connect automatically to port 27017(localhost).
I have also noticed that I started to have the error after the addition to the pom.xml of the dependency to spring-boot-starter-web.
How can I inhibit Spring Boot to try to connect automatically to Mongo at startup? The same problem is present with the synchronous version of MongoDB driver.
--- EDIT ---
I have also try to build a wrapper around the async.MongoClient object, in this way:
public class MongoWrapper {
private final MongoClient mongo;
public MongoWrapper() {
mongo = MongoClients.create();
}
public MongoClient getMongo() {
return mongo;
}
}
The configuration was changed accordingly.
#Bean
public MongoWrapper mongo() {
return new MongoWrapper();
}
Unfortunately, nothing had changed. Spring Boot seems to intercept the MongoClient object also in this way :(
Thanks a lot.
You have a MongoClient bean in your own configuration which does not make any sense to me if you've excluded the auto-configuration.
I've commented out the #Bean definition in your own config and no attempt to connect to Mongo is performed now. I am not sure I answer to your question and you're probably looking for something else but if you don't want to use mongo, don't define a MongoClient in your own config!
This helped us to disable async java driver of MongoDB to use default configuration:
#EnableAutoConfiguration(exclude = {MongoReactiveAutoConfiguration.class})

errors starting a simple spring boot application

Im trying to run a simple spring boot application, i have filled the application.properties with appropriate parameters to creat a datasource based on jpa and mysql configuration, and i have specified in the pom.xml some of the dependencies that my application may require in order to run, but i still get the same error when i start my application, here is my configuration files, i hope i can get some help here !
i want the application to create in my database the table using orm techonolgy for the begining but im stuck with these errors !!
pom.xml file
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>objectExchange</groupId>
<artifactId>exchange</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>objectExchange</name>
<description>ObjectExchange Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</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-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-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
the application.properties file
spring.datasource.url = jdbc:mysql://localhost:3306/db_objexchange
spring.datasource.username = root
spring.datasource.password =
spring.datasource.driverClassName = com.mysql.jdbc.Driver
spring.jpa.database = MYSQL
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
the application file :
package com;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class ObjectExchangeApplication {
public static void main(String[] args) {
SpringApplication.run(ObjectExchangeApplication.class, args);
}
}
the class for persistance with jpa
package com.entities;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
#Entity
public class utilisateur implements Serializable {
#Id
#GeneratedValue
private Long id;
private String nom;
private String prenom;
public utilisateur() {
super();
}
public utilisateur(Long id, String nom, String prenom) {
super();
this.id = id;
this.nom = nom;
this.prenom = prenom;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
}
this are the file i have on my application and i keep getting these errors :
:: Spring Boot :: (v1.4.1.RELEASE)
2016-09-25 19:59:02.908 INFO 4952 --- [ main] com.ObjectExchangeApplication : Starting ObjectExchangeApplication on user-PC with PID 4952 (C:\Users\user\workspace\objectExchange\target\classes started by user in C:\Users\user\workspace\objectExchange)
2016-09-25 19:59:02.918 INFO 4952 --- [ main] com.ObjectExchangeApplication : No active profile set, falling back to default profiles: default
2016-09-25 19:59:03.277 INFO 4952 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#1eb5ee5: startup date [Sun Sep 25 19:59:03 WEST 2016]; root of context hierarchy
2016-09-25 19:59:05.193 WARN 4952 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:/C:/Users/user/.m2/repository/mysql/mysql-connector-java/5.1.39/mysql-connector-java-5.1.39.jar!/com/mysql/fabric/FabricCommunicationException.class]; nested exception is java.util.zip.ZipException: invalid LOC header (bad signature)
2016-09-25 19:59:05.284 ERROR 4952 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:/C:/Users/user/.m2/repository/mysql/mysql-connector-java/5.1.39/mysql-connector-java-5.1.39.jar!/com/mysql/fabric/FabricCommunicationException.class]; nested exception is java.util.zip.ZipException: invalid LOC header (bad signature)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:303) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:248) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:137) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:275) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:237) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:204) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:173) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:324) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:246) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:98) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:523) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at com.ObjectExchangeApplication.main(ObjectExchangeApplication.java:10) [classes/:na]
Caused by: java.util.zip.ZipException: invalid LOC header (bad signature)
at java.util.zip.ZipFile.read(Native Method) ~[na:1.8.0_92]
at java.util.zip.ZipFile.access$1400(Unknown Source) ~[na:1.8.0_92]
at java.util.zip.ZipFile$ZipFileInputStream.read(Unknown Source) ~[na:1.8.0_92]
at java.util.zip.ZipFile$ZipFileInflaterInputStream.fill(Unknown Source) ~[na:1.8.0_92]
at java.util.zip.InflaterInputStream.read(Unknown Source) ~[na:1.8.0_92]
at java.io.FilterInputStream.read(Unknown Source) ~[na:1.8.0_92]
at java.io.BufferedInputStream.fill(Unknown Source) ~[na:1.8.0_92]
at java.io.BufferedInputStream.read1(Unknown Source) ~[na:1.8.0_92]
at java.io.BufferedInputStream.read(Unknown Source) ~[na:1.8.0_92]
at org.springframework.asm.ClassReader.readClass(ClassReader.java:463) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.asm.ClassReader.<init>(ClassReader.java:426) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:53) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:98) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:279) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
... 19 common frames omitted
I really hope i can get some help as soon as possible, and thank you all so much !!
Your error is this:
Failed to read candidate component class: URL
[jar:file:/C:/Users/user/.m2/repository/mysql/mysql-connector-java/5.1.39/mysql-connector-java-5.1.39.jar!/com/mysql/fabric/FabricCommunicationException.class];
nested exception is java.util.zip.ZipException: invalid LOC header
(bad signature)
This suggests that mysql-connector-java-5.1.39.jar is corrupt.
Solution
Remove C:/Users/user/.m2/repository (or at the very least C:/Users/user/.m2/repository/mysql/mysql-connector-java/).
This will force maven to redownload mysql-connector-java's jar when you rebuild (ie: mvn clean install).
Include the dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
instead of
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
in your POM.xml
Another issue could be the mysql jar located in your .m2 folder. Try to delete the jar file, update your pom.xml and try again.
Working on project I stumble upon the not exact, but rather similar error.
Caused by: org.apache.ignite.IgniteCheckedException: Failed to find configuration in: org.springframework.boot.loader.jar.ZipInflaterInputStream#...
In my case the real reason for such error was removing one parameter inside SpringBoot configuration XML file. I don't see real reason for error but fact is....
Correct config runs without errors is below:
<beans profile="local,default">
<bean class="org.apache.ignite.configuration.IgniteConfiguration">
The incorrect configuration causing the same error was removed 'default' param:
<beans profile="local">
<bean class="org.apache.ignite.configuration.IgniteConfiguration">
The last configuration was caused the same error on SpringBott app start-up.
The configuration parameters in my case are related to Apache Ignite. Cleaning up /.m2/ and Gradle cache folders didn't help.
As one more solution can be running application with specifying explicit Spring profile like:
java -jar -Dspring.profiles.active=local xxx_YOUR_FAT_JAR-FILE.jar

Categories

Resources