Errors right after creating Spring Boot Application in IntelliJ - spring

After creating the Spring Boot application in IntelliJ IDEA, it has errors. I didn't edit the code. It can't find org.spring.boot.SpringApplication. I've tried to create the app several times but no effect. All needed plugins are in the IDE, switched on. Maybe someone already had the problem
Errors in code
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class DemoApplication {
public static void main(String[] args)
{
SpringApplication.run(DemoApplication.class, args);
}
}
Errors in console
Cannot resolve org.springframework.boot:spring-boot-autoconfigure:2.4.4
Cannot resolve jakarta.annotation:jakarta.annotation-api:1.3.5
Cannot resolve org.ow2.asm:asm:5.0.4
Cannot resolve org.junit.platform:junit-platform-engine:1.7.1
Cannot resolve com.fasterxml.jackson.core:jackson-core:2.11.4
Cannot resolve jakarta.xml.bind:jakarta.xml.bind-api:2.3.3
Cannot resolve org.apache.tomcat.embed:tomcat-embed-websocket:9.0.44
Cannot resolve com.fasterxml.jackson.core:jackson-databind:2.11.4
Cannot resolve org.glassfish:jakarta.el:3.0.3
Cannot resolve org.springframework.security:spring-security-web:5.4.5
Cannot resolve org.springframework.boot:spring-boot-test:2.4.4
Cannot resolve org.springframework:spring-aspects:5.3.5
Cannot resolve org.springframework:spring-web:5.3.5

Right click on the pom.xml and select Maven -> Reload Project

Related

org.springframework.boot.SpringApplication import throwing error

I am working on this tutorial using Spring Tool Suites.
I've copied what it says and my code and pom look the same (copied for easy review)
package com.javatpoint.spring_boot_example_sts;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class SpringBootExampleSts
{
public static void main(String[] args){
SpringApplication.run(SpringBootExampleSts.class, args);
}
}
My issue is that I am getting a red line under ' org.springframework.boot.SpringApplication. To my knowledge, this library is not deprecated and I can't seem to find any instance of it being moved.
Thanks in advance.
May be maven either maven dependency is not downloaded or your IDE has some issues.
You can try to restart your IDE.
If issue still persist, Please build using mvn clean package.

Spring Boot Application error: Exception in thread "main" java.lang.NoSuchMethodError

Why i'm getting this error while running simple SpringBoot Application.
Exception in thread "main" java.lang.NoSuchMethodError:
org.springframework.boot.SpringApplication.run(Ljava/lang/Class;[Ljava/lang/String;)Lorg/springframework/context/ConfigurableApplicationContext;
at
io.javabrain.springbootstarter.CourseApiApp.main(CourseApiApp.java:10)
package io.javabrain.springbootstarter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class CourseApiApp {
public static void main(String[] args) {
SpringApplication.run(CourseApiApp.class, args);
}
}
It should be running successfully
For gradle project in gradle\wrapper\gradle-wrapper.properties file change distributionUrl variable to:
distributionUrl=https://services.gradle.org/distributions/gradle-4.7-bin.zip
If it is don't helps download project from https://start.spring.io/ and do the same.
If you use maven, just download maven project from https://start.spring.io/ . It should work fine.

kotlin and spring boot error in Intellij

I'm creating a Kotlin project with Spring boot and Gradle project fromstart.spring.io
When importing this project to IntelliJ and run the project(Alt+Shift+F10) then show this error
Error: Could not find or load main class com.example.demo.DemoApplicationKt
mainclass :
package com.example.demo
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
#SpringBootApplication
class DemoApplication
fun main(args: Array<String>) {
SpringApplication.run(DemoApplication::class.java, *args)
}
How can I solve this problem?
You can run the application by clicking the run button(play button) which is on the left side of the main class as shown in below picture.
If you run like this, it will automatically create run configuration

User authentication failing after upgrading to 3.2.1

I just upgraded my app from Grails 3.2.0 to 3.2.1 due to some problems and the user authentication started failing. I'm using Grails Spring Security Core plugin version 3.1.1.
I'm getting the following exception:
org.springframework.security.authentication.InternalAuthenticationServiceException:
Cannot cast object 'User(email:user#example.com)' with class 'com.test.User' to class 'com.test.User'
at org.springframework.security.authentication.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:126)
at org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:144)
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:174)
at org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter.attemptAuthentication(UsernamePasswordAuthenticationFilter.java:94)
at grails.plugin.springsecurity.web.authentication.GrailsUsernamePasswordAuthenticationFilter.attemptAuthentication(GrailsUsernamePasswordAuthenticationFilter.groovy:53)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:212)
Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException:
Cannot cast object 'User(email:user#example.com)' with class 'com.test.User' to class 'com.test.User'
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405)
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319)
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:603)
at com.test.User.findWhere(User.groovy)
at com.test.User$findWhere.call(Unknown Source)
at grails.plugin.springsecurity.userdetails.GormUserDetailsService.$tt__loadUserByUsername(GormUserDetailsService.groovy:60)
at grails.plugin.springsecurity.userdetails.GormUserDetailsService$_loadUserByUsername_closure1.doCall(GormUserDetailsService.groovy)
This is only failing when we deploy it on Apache Tomcat (using 8.5.6) but it is working fine on development with grails run-app.
Here are the modified dependencies in build.gradle (rest configuration is same as generated by create-app):
// "compile" changed to "provided"
provided "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails.plugins:spring-security-core:3.1.1"
compile "org.grails.plugins:asynchronous-mail:2.0.0.RC4"
compile "org.mongodb:bson:3.3.0"
compile "org.codehaus.groovy.modules.http-builder:http-builder:0.7.1"
runtime "mysql:mysql-connector-java:5.1.39"
// https://github.com/spring-projects/spring-boot/issues/6761
runtime "com.google.code.gson:gson:2.5"
// Commented this to avoid issue (https://github.com/grails/grails-core/issues/10196)
//provided "org.codehaus.groovy:groovy-ant"
The same setup was working in the Grails 3.2.0.
Any idea about this exception?
Seems to be an issue with Grails 3.2.1 itself. Issue tracked grails/grails-core#10244.
Workaround is to override limitScanningToApplication in your grails-app/init/PACKAGE/Application.groovy
import grails.boot.GrailsApp
import grails.boot.config.GrailsAutoConfiguration
class Application extends GrailsAutoConfiguration {
static void main(String[] args) {
GrailsApp.run(Application, args)
}
#Override
boolean limitScanningToApplication() {
return false
}
}

org.springframework.boot.autoconfigure cannot be resolved in eclipse

I imported the spring-boot-1.1.10.RELEASE.jar into my j2ee project.
But i can not found the class of autoconfigure.
Here is code:
import org.springframework.boot.autoconfigure;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;
#ComponentScan
#EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
The Compile error:
The import org.springframework.boot.autoconfigure cannot be resolved
I had the same problem and I tried above solutions. But I have found a different issue.
In latest springframework, this org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder has been moved to
org.springframework.boot.jdbc.DataSourceBuilder. so you have to edit in import
And then you will notice that you have to use DataSourceBuilder.create(classLoader)
instead of new DataSourceBuilder(classLoader)
Go to your maven repository directory
For windows on below path
C:\Users\YourUser\.m2\repository\org\springframework\boot
Then delete spring-boot-autoconfigure folder.
Now go to eclipse and do maven update.
There is a copy/paste error - the code from the official documentation (https://spring.io/guides/gs/rest-service/) is:
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;
#ComponentScan
#EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
The code in the question is missing ".EnableAutoConfiguration" in the first line.
In case anyone else has this issue, I was able to solve this by deleting the spring-boot-autoconfigure artifacts from my local Maven repository and updating my project in Eclipse (which re-downloads the artifacts).
if you are using eclise then Right button on project -> Maven -> Update Project
If you are using IntelliJ IDEA Right click on project -> Maven -> Reimport
Also, try "Generate source and update folder" below the reimport if above method doesn't work. No need to delete any spring or maven folder or files.

Resources