English 中文(简体)
我拿到“Cannot resolutioncode web”,试图进口org. Cerframework.web。 然而,我的om子说,我需要一切。
原标题:I get "Cannot resolve symbol web " trying to import org.springframework.web. Yet my pom.xml says I have everything required

我是 Java新布和新布。 在我尝试学习新语言时,学习的 Lo。 我知道Pytnon和JS是参考点。

我正试图将一个被遗弃的“团结互助会”项目中的代码复制成一个新的项目。 我正在着手进行一系列长途和风 the的工作,关于组群的第一组工作是:<条码>进口 org. Cerframework.web.bind.annotation.GetMapping;。 web和 当我改动时,不能解决文号网站

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);
    }

}

我曾尝试修改<代码>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>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>

在另一个档案中,我也存在同样的问题:import org. merframework.jdbc.datasource. ZhangrManagerDataSource; 给“Cannot resolution jdbc” on mouseover,而进口则显示红色。

mvn Pack>就一个无关的错误作了说明,因此,我认为它只是一个英特尔利J IDEA问题。 这里有错误:

***************************
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.

因此,我尝试修改了pom.xml,并尝试了mvn Cleanstal-U,并放弃了我的电离层。 我将尝试更多的事情,但是,作为在贾瓦的新布,我不敢肯定会做什么!

此外,这 does不回。 然而,我仍然看着几个小时。

edit: issue while importing org.springframework.web : cannot resolve symbol web looks related, but it s 4 years old and unanswered!

问题回答

I tried right clicking the red and choosing "Context Actions" from the IDEA dropdown and then picking something about looking on the web for the package. I don t recall what the specific text said. Anyway: It worked! My red error text is gone. Oddly git diff shows 0 changes so I guess it was an IDEA centric issue and not the code or pom.xml file





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签