I am a Java newb and a Spring Boot newb. Lots of learning going on as I try to learn a new language. I know Pytnon and JS as reference points.
I am in the midst of trying to copy over code from an abandoned CRUD project into a new one. I am working through the start of a long and winding series of bugs, and the first on the chopping block is that import org.springframework.web.bind.annotation.GetMapping;
highlights red over web
and says Cannot resolve symbol 'web'
when I mouse over it.
Here is some code with comments indicating where the red is
package com.example.bookscrud.book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; // here
import org.springframework.web.bind.annotation.PostMapping; // here
import org.springframework.web.bind.annotation.RequestBody; // here
import org.springframework.web.bind.annotation.RestController; // here
import java.util.List;
@RestController
@RequestMapping(path = "api/v1/books")
public class BooksController {
private final BookService BookService;
@Autowired // magic
public BooksController(BookService BookService) {
this.BookService = BookService;
}
@GetMapping(value = "/")
public List<Book> getBooks() {
return BookService.getBooks();
// return List.of(Book, bart);
}
}
I made some attempts to modify the pom.xml
thinking maybe I missed some crucial import. But no, doesn't look that way.
<?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>3.1.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>books-crud</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>books-crud</name>
<description>Books CRUD app</description>
<properties>
<java.version>17</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</groupId>
<artifactId>spring-web</artifactId>
<version>6.0.5</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</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>
I have a similar problem in another file: import org.springframework.jdbc.datasource.DriverManagerDataSource;
gives "Cannot resolve symbol 'jdbc'" on mouseover, and the imports show red.
mvn package
says something about an unrelated error, making me think its just an IntelliJ IDEA issue. Here's the error:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method BookRepository in com.example.bookscrud.book.BookRepositoryImpl required a bean of type 'javax.sql.DataSource' that could not be found.
Action:
Consider defining a bean of type 'javax.sql.DataSource' in your configuration.
I am using IntelliJ IDEA as my IDE.
So, I tried modifying the pom.xml, also tried mvn clean install -U
, and restarting my IDE. I would try more things but, being a newb at Java, I'm not sure what to do!
Additionally, googling this doesn't return much. I'm still looking though, have been for a few hrs.
edit: issue while importing org.springframework.web : cannot resolve symbol 'web' looks related, but it's 4 years old and unanswered!