No qualifying bean - FxWeaver and Spring Boot - java

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.

Related

Spring boot not compiling due to QClass missing

Hi im new to spring boot, ive been trying to integrate querDSL into my project but every time I package it it gives me errors. For example it would say my QClasses would not exist even though they have been properly imported through maven. Ive tried different versions of queryDSL but have come to no solution. I think its an issue with my pom file though I'm not sure as I had followed the tutorial made by Baeldung. Any advice would help, thank you.
My exact error
Error:(11, 8) java: cannot access com.querydsl.core.types.OrderSpecifier
class file for com.querydsl.core.types.OrderSpecifier not found
This is in the Repo class below
My 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 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.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>rc</groupId>
<artifactId>springboot-mongodb-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot-mongodb-demo</name>
<description>Demo project for Spring Boot with Mongo Db</description>
<properties>
<java.version>1.8</java.version>
<querydsl.version>4.1.3</querydsl.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</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.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>4.1.3</version>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-mongodb</artifactId>
<version>3.6.6</version>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>3.6.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>
org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor
</processor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
My Repo Layer code
package rc.springbootmongodbdemo;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.stereotype.Repository;
import java.util.*;
#Repository
public interface HotelRepository extends MongoRepository<Hotel, String>, QuerydslPredicateExecutor<Hotel> {
Hotel findByID(String id);
List<Hotel> findByPricePerNightLessThan(int maxPrice);
#Query(value = "{address.city:?0}")
List<Hotel> findByCity(String city);
}
check this question answered before
Spring Boot+JPA+QueryDSL=OrderSpecifier not found
also go through this
https://www.baeldung.com/intro-to-querydsl
SOLUTION:
I had a repository class that was extending MongoRepository. I was passing in the following
public interface HotelRepository extends MongoRepository<Hotel, String>, QuerydslPredicateExecutor<Hotel>{
after removing:
QuerydslPredicateExecutor
My error went away and my program began running again as it should.
I feel like the querydslpredicateexecutor is maybe an older code format and it wasn't compiling into my new version. Just a theory.

error:java package xxx does not exist despite IDEA being aware of them

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.

Unable to start web server due to missing ServletWebServerFactory

I have looked on Stack Overflow a few days ago. My problem seems to be very common, but I cannot manage to fix it.
I've tried these ways 1 and 2.
This is my application.propreties :
spring.datasource.driver-class-name= org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5433/mydatabase
spring.datasource.username=username
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=create
spring.main.web-application-type=none
When I tried to run it, it is giving me following errors :
org.springframework.context.ApplicationContextException: Unable to start web server;
nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean
These is my main class:
#SpringBootApplication
public class StartApplication {
#Autowired
BookRepository repository;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
and this is my 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>toto</groupId>
<artifactId>toto</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
</plugins>
</build>
</project>
Thanks in advance for your help.
You should remove the following property from your application.properties file
spring.main.web-application-type=none
it means that you don't need a web server in your application.
I'm not a pro programmer, but what I would do if I were you :
Make sure you have a proper project structer
Check the basic configuration guides fromSpring.io!
I have my personal project where I training with Spring Framework usage, maybe you will get something usefull from it,project link!
Good luck and have fun :)
Your main class should be like:
#SpringBootApplication
public class StartApplication {
#Autowired
BookRepository repository;
public static void main(String[] args) {
SpringApplication.run(StartApplication.class, args);
}
}

Spring Boot and Vaadin UI not accessible?

I set up a spring boot vaadin project and implemented this class according to springs tutorial, but cannot access the ui with localhost:8080/ui. What am I doing wrong?
My UI class:
package net.lawyd.server.ui;
import com.vaadin.annotations.Theme;
import com.vaadin.server.VaadinRequest;
import com.vaadin.spring.annotation.SpringUI;
import com.vaadin.ui.Button;
import com.vaadin.ui.Notification;
import com.vaadin.ui.UI;
#SpringUI(path = "/ui")
#Theme("valo")
public class VaadinUI extends UI {
#Override
protected void init(VaadinRequest request) {
setContent(new Button("Click me", e -> Notification.show("Hello Spring+Vaadin user!")));
}
}
Here is my Spring configuration class:
package net.lawyd.server.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;
#Configuration
#ComponentScan("net.lawyd.server")
#EnableJpaRepositories("net.lawyd.server")
#EnableTransactionManagement
public class SpringConfig {
// Nothing to do here
}
Here is my 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>net.lawyd</groupId>
<artifactId>lawyd-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<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-jersey</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
[UPDATE 1] I noticed this log message:
Cannot enhance #Configuration bean definition
'com.vaadin.spring.VaadinConfiguration' since its singleton instance
has been created too early. The typical cause is a non-static #Bean
method with a BeanDefinitionRegistryPostProcessor return type:
Consider declaring such methods as 'static'.
[UPDATE 2] I created an empty spring boot application using start.spring.io and inserting the demo from the tutorial. It works there, so it has to be something with my setting.
[UPDATE 3] I figured out it has something to do with the JerseyConfig, when I take it out it Vaadin works, but jersey does not anymore:
#SpringBootConfiguration
public class JerseyConfig extends ResourceConfig {
public JerseyConfig() {
register(TodoResource.class);
register(HealthResource.class);
}
}
Here is also the code on github.
I found the root problem: Jersey was mapped to the root, so all the calls on root were intercepted. Changing the #ApplicationPath("/api") to something other than root solved the problem:
#SpringBootConfiguration
#ApplicationPath("/api")
public class JerseyConfig extends ResourceConfig {

Unable to access and use static resources in Spring Boot Application

I have been fighting with getting resources to work for quite sometime now, and I know there are thousands of similar questions.. Anyway, my condition is this
I will start with my pom.. I might have missed something here?
<?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.ruruapps</groupId>
<artifactId>spring-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-demo</name>
<description>Spring-Demo Application</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.thymeleaf-version>2.1.4</org.thymeleaf-version>
<webjars-bootstrap.version>3.3.5</webjars-bootstrap.version>
<webjars-jquery-ui.version>2.1.1</webjars-jquery-ui.version>
<webjars-jquery.version>2.0.3-1</webjars-jquery.version>
<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-batch</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-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</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-security</artifactId>
</dependency>
<!-- Thymeleaf -->
<!--<dependency>-->
<!--<groupId>org.thymeleaf</groupId>-->
<!--<artifactId>thymeleaf</artifactId>-->
<!--<version>2.1.4.RELEASE</version>-->
<!--</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- Webjars (static dependencies distributed as WAR files) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</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>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.5</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>2.1.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Here are the errors I am dealing with
And in the terminal I see this
Looking up handler method for path /css/bootstrap/css/bootstrap.min.css
Did not find handler method for [/css/bootstrap/css/bootstrap.min.css]
Request method 'GET' not supported
What does this mean?
I have a correct structure and doing it by the convention
But no luck what so ever. I tried changing to public/ and tried using webjars. All in vain. What are the norms for this and how do I get this set up so it wont be breaking! Thanks!
EDIT:: Configuration Files
Here is my application file that is provided with the spring boot
#SpringBootApplication
#EnableAutoConfiguration(exclude = {
org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration.class,
org.springframework.boot.actuate.autoconfigure.ManagementSecurityAutoConfiguration.class})
#ComponentScan(basePackages = {"webapp"})
#EnableJpaRepositories
public class SpringDemoApplication {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(SpringDemoApplication.class, args);
}
}
And I have a WebConfig file which is mostly empty, but I tried adding the #Overide on addResourceHandlers, with no improvements
#Configuration
#EnableWebMvc
#ComponentScan(basePackages = {"webapp"})
public class WebConfig extends WebMvcConfigurerAdapter {
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("classpath:/resources/static/").setCachePeriod(31556926);
}
}
EDIT
After further examining the application, I have found this
It says that the request it allows is PUT, but why? From what I can understand is that something is blocking my request to the resource files, is that right?
Desperate to get this fixed, it's really bothering to configure Spring, even with Spring Boot!
Found a problem that I was facing with not being able to access static resources.
For those who experience the same:
This behaviour (405 error) signifies that something is blocking the path to your static resources. This doesn't have to be /static or /public. It wont do anything.
In my case the problem was that a controller was blocking the /css path. To fix this a #RequestMapping(value = "/Somepath") annotation on the class lvl is needed to release the path for the static resources.
This worked for me and now I can access my static resources without any issues.
This can be a very annoying problem and someone can spend hours and days trying to figure this out. Hope this helps others to save their time
If there are alternative or other methods of preventing this behaviour that please mention in the comments
If you are trying to configure resource mapping through configuration class as you mentioned in comment, then it should be like this:
#EnableWebMvc
#ComponentScan(basePackages = {"org.company.yourpackage"})
#Configuration
public class AppConfig extends WebMvcConfigurerAdapter {
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("classpath:/resources/static/").setCachePeriod(31556926);
}
}
this post also may help.
I was having the exact same issue, What helped me was adding:
enter code here
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
OR
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/js/*</url-pattern>
</servlet-mapping>
from this post
servlet for serving static content here

Categories

Resources