I have a very simple JUnit test class that I can not run unless I remove parent spring-boot-starter-parent from the pom, which wouldn't be a possibility for our production application. The error we get on is No Tests Were Executed and below is the mvp with the parent piece that whenever not commented out would block the tests. If I can get any guidance to know how to fix this please.
<?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>
<!-- Piece to be disabled for tests to run -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.hmhco</groupId>
<artifactId>crs-v2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>crs-v2</name>
<description>Content Recommendation Service V2</description>
<properties>
<java.version>1.8</java.version>
<junit.jupiter.version>5.6.2</junit.jupiter.version>
<maven.surefire.version>3.0.0-M5</maven.surefire.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
</plugin>
</plugins>
</build>
import org.junit.jupiter.api.Test;
public class TestingTest {
#Test
public void checking() {
System.out.println("checking------------");
}
}
Thank you.
The problem is related to that you trying to use a different version of junit jupiter. The version which is predefined by spring-boot-parent (2.2.4.RELEASE) is 5.5.2. The simplest solution is to remove the versions of junit-jupiter parts (version tag) and use the one which is inherited from spring-boot-parent. The best recommendation I can give is to start with a newer version of Spring Boot (2.3.3.RELEASE most recent one) which uses a more recent version.
If you can't go that way you have to use the junit-bom file instead like this:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.6.2</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Then it should work fine. Afterwards you have to use the dependencies without defining the version tag anymore in your pom.xml file.
Adding -DfailIfNoTests=false to the mvn command seems to make it work.
Related
I have added logback-spring.xml into the class path and it was working fine until I added below dependencies for some ISO message conversion.(crimson dependency is hardcoded in the JPOS library, so it cannot be removed)
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.7</version>
<relativePath/>
</parent>
<groupId>com.test</groupId>
<artifactId>iso-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>iso-test</name>
<description>test</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>2.4.4</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jpos</groupId>
<artifactId>jpos</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>crimson</groupId>
<artifactId>crimson</artifactId>
<version>1.1.3</version>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Then there is an issue with logback-spring.xml reading with below exceptions.
java.lang.IllegalStateException: Could not initialize Logback logging from classpath:logback-spring.xml'
and
Caused by: org.xml.sax.SAXNotSupportedException: Feature: http://xml.org/sax/features/external-general-entities
Below is where the JPOS packager(GenericValidatingPackager.class) used crimson library.
public void readFile(String filename) throws ISOException {
XMLReader reader=XMLReaderFactory.createXMLReader(System.getProperty("sax.parser", "org.apache.crimson.parser.XMLReaderImpl"));
...
}
crimson dependency is hardcoded in the JPOS library, so it cannot be removed
This is not correct, referring to JPOS packager(GenericValidatingPackager.class)
XMLReader reader = XMLReaderFactory.createXMLReader(System.getProperty("sax.parser", "org.apache.crimson.parser.XMLReaderImpl"));
This line just tell us that if we do not set the property "sax.parser", we use
org.apache.crimson.parser.XMLReaderImpl as fallback.
So what we need:
Remove crimson dependency
set the property "sax.parser", e.g.
System.setProperty("sax.parser", "com.sun.org.apache.xerces.internal.parsers.SAXParser");
Crimson is not required by jPOS if you use a modern JVM (1.8 and up).
It was used in the past, as a fallback if the JVM didn't provide an XMLReader, and org.xml.sax.driver was not configured.
Also, I suggest to use the latest version (see ChangeLog) as there has been a lot of improvements since 2.1.0 back in 2017.
I'm getting this kotlin exception when trying to run some PACT tests using Java and not sure how to fix it please.
Here the error :
Exception in thread "Thread-2" java.lang.NoSuchMethodError:
kotlin.io.ByteStreamsKt.readBytes(Ljava/io/InputStream;)[B
EDIT
I've updated my PACT dependencies to use more up to date versions, and I'm still getting the same issue, however only when I have the below dependency as part of it and not sure why.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
</parent>
This is my current pom:
<?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.hmhco</groupId>
<artifactId>update-catalog</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
</parent>
<properties>
<rest-assured.version>3.0.0</rest-assured.version>
<json-schema-validator.version>3.3.0</json-schema-validator.version>
</properties>
<dependencies>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>${rest-assured.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-schema-validator</artifactId>
<version>${json-schema-validator.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-consumer-junit5</artifactId>
<version>4.0.10</version>
</dependency>
<dependency>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-provider-junit</artifactId>
<version>4.0.10</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-provider-maven</artifactId>
<version>4.0.10</version>
<configuration>
<pactDirectory>target/pacts</pactDirectory>
<pactBrokerUrl>http://pact-broker-hmh.devel.hmheng-qe.brnp.internal/</pactBrokerUrl>
<projectVersion>${project.version}</projectVersion>
<trimSnapshot>true</trimSnapshot>
</configuration>
</plugin>
</plugins>
</build>
And that's what I see when look for Kotlin after running maven dependency tree. The complete project can be found here.
Thanks very much.
A possible reason you are getting that error (I'm assuming) is because you are mixing major versions of the Pact libraries.
<pact.version>3.5.24</pact.version>
<pact-jvm-provider-maven.version>3.5.9</pact-jvm-provider-maven.version>
<pact-jvm-maven.version>3.5.24</pact-jvm-maven.version>
<pact.jvm.consumer.junit.version>4.0.10</pact.jvm.consumer.junit.version>
You have versions 3.5.9, 3.5.24 and 4.0.10. You should use the same major version.
Versions 3.5.x are mostly written in Kotlin (probably version 1.2.x), while version 4.0.x is written using Kotlin 1.3.x.
I'm not sure why Sprinboot is impacting things, but maybe a Spring dependency is also bringing in a version of the Kotlin standard library.
The best thing to do is use version 4.0.10 for all the Pact libraries, then run the Maven dependency tree plugin and check that versions of the Kotlin standard libraries that are being used.
I am trying to refactor a Java program I wrote last year to use Spring Boot. The front end uses JavaFX, and so I am trying to use FxWeaver.
However, when I run my program, I get the following error on startup:
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:835)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'net.rgielen.fxweaver.core.FxWeaver' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:351)
...
From rgielen's website, it shouldn't be necessary to provide an RxWeaver "... when using the Spring Boot Starter, since it provides auto-configuration for a FxWeaver instance."
So I'm stumped as to why I'm getting this error. Would anyone be able to take a look please?
Main Application
package application;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import javafx.application.Application;
#SpringBootApplication
public class MainApplication {
public static void main(String[] args) {
Application.launch(SpringbootJavaFxApplication.class, args);
}
}
SpringBootJavaFxApplication
package application;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import net.rgielen.fxweaver.core.FxWeaver;
public class SpringbootJavaFxApplication extends Application {
private ConfigurableApplicationContext applicationContext;
#Override
public void init() throws Exception {
this.applicationContext = new SpringApplicationBuilder()
.sources(MainApplication.class)
.run(getParameters().getRaw().toArray(new String[0]));
}
#Override
public void start(Stage stage) {
FxWeaver fxWeaver = applicationContext.getBean(FxWeaver.class);
Parent root = fxWeaver.loadView(Controller.class);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
#Override
public void stop() {
this.applicationContext.close();
Platform.exit();
}
}
pom
<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>xxxxx</groupId>
<artifactId>xxxxx</artifactId>
<version>1.0</version>
<name>xxxxx</name>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>12.0.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.rgielen</groupId>
<artifactId>javafx-weaver-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>application.Main</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
(Obviously the pom contains things not specifically related to this issue, but I'm including the whole file in case anything else present is causing this issue.)
Please can you let me know if you have worked out what is causing the problem? I'm tearing my hair out with this now!
Also, apologies if I've not included the right/sufficient information. This is my first post on here. I am using eclipse.
Thank you!
Maybe I'm too late to help, but:
I re-created an example based on a minimal pom and your Java code. I could not re-produce your issue, though.
Here is my pom:
<?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">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>net.rgielen.sample</groupId>
<artifactId>fxweaver-springboot-starter-sample</artifactId>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</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>net.rgielen</groupId>
<artifactId>javafx-weaver-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
What concerns me with your pom
it adds a dependency on OpenJFX 12 (targeted at JDK 12), but compiles with target 1.8 - which in a Spring Boot application would be easier to define with the java.version property. When using a 1.8 JRE with embedded JavaFX (Oracle, Liberica) you would not need OpenJFX deps at all
You don't need javafx-maven-plugin when packaging as Spring Boot application.
That said, I fail to see this as root cause.
If you want to compare in detail, here's the code:
https://github.com/rgielen/fxweaver-springboot-stripped-demo
Just a brief update for anybody who finds this in future. I was unable to resolve the problem in the end, so instead went for a full refactor of the code, without the use of FxWeaver.
More labour-intensive, but the resulting code is arguably much better as a result.
I had the same problem.
I checked Spring conditions evaluation report and found this:
FxWeaverAutoConfiguration:
Did not match:
- #ConditionalOnClass did not find required class 'javafx.fxml.FXMLLoader' (OnClassCondition)
So I put dependency on javafx-fxml
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>12.0.2</version>
</dependency>
And the condition was satisfied.
This worked for me.
I'm leanring springboot with some source code.Recent days,when I begin learning new lessons and want to import the example project I found I fail to import all the packages when I open the example project. Although previous example projects works fine.
It's especially strange that the editor actually can identify those packages - it even offered me the appropriate classes when I manually deleted the import statements, I can see the library in the Project tree under External Libraries,I even can skip to see where the package is through ctrl+click. However, I always get a list of "java: package ... does not exist" upon compilation.How should I solve the problem?Thanks!!
I hava tried following solutions:
reimport in maven settings
invalidate and restart
3.check pom.xml
my 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.neo</groupId>
<artifactId>spring-boot-file-upload</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
some of the wrong import
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.multipart.MultipartException;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
error messages while compiling:
fail to import all the packages
therefore can't resolve all the related symbols
Your project is missing some dependencies. You are not only using Spring Boot, but also Spring Web and Spring MVC.
Try adding this to your pom.xml:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.1.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.9.RELEASE</version>
</dependency>
You may want to adapt depending on the Spring version you are using.
I have read various SO question, spring tutorials and looked at different example projects, but i still do not get it.
Among others were these:
unable to connect spring with mysql
http://www.codejava.net/frameworks/spring/spring-mvc-with-jdbctemplate-example
My goal is to get a GRADLE spring boot/web application that connects to my MySql database.
My problem is there are many different ways to configure your project.
I would like to use as few XML as possible.
So my question is, whether it is possible to achieve my goal without having a single XML file and if so - how?
Or if i need an XML file(it should then be the pom.xml I think).
I would like an explanation why I need it and what the file does in general.
Please NOTE: I have about zero knowledge how to configure spring, mysql, hibernate.
So also things that may be straightforward for you, could be unclear to me.
So I would really appreciate explanantions.
EDIT2:
I got an sample application running using Spring Initializer
BUT, this sample application uses Maven - to be exactly it uses this 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>
<groupId>org.test</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.2.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>demo.DemoApplication</start-class>
<java.version>1.7</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-jdbc</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>
</project>
Is there an eaasy way I can replace this code with gradle or some kind of tutorial that tells me how to replace this code with the correct gradle file?
The simplest way may be for you to download a "bootstrapped" project using the Spring Initializr. You can select the dependencies that you require and the build system, and it will generate your project for you.
For Spring Boot to connect to your MySQL instance, it should be sufficient to just have the following properties in your application.properties file:
spring.datasource.url=jdbc:mysql://localhost:3306/db
spring.datasource.username=user
spring.datasource.password=password
See the Spring Boot Reference for Working with SQL databases for more information.