导入org.springframework.security无法解析

user12398352:

我得到一个错误

导入org.springframework.security无法解决。

我搜索了一下,也许我错过了一个依赖项,必须添加它,我不知道,请帮助我。我正在给我我的pom.xml文件和java类。如果有人可以帮助我,我将非常感谢

这是我的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.2.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>Music</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>Music</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <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-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </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-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

和我的java课

package masters.rest;

import java.util.List;
import java.util.Optional;

import javax.servlet.http.HttpSession;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import masters.beans.CommentBean;
import masters.beans.UserBean;
import masters.repositories.CommentRepo;


@RestController
public class Comment {

    CommentRepo commentRepo;

    public Comment(CommentRepo commentRepo) {
        this.commentRepo = commentRepo;
    }

    @DeleteMapping(path = "/comment/delete")
    @Secured("ROLE_ADMIN")
    public ResponseEntity<Boolean> deleteComment(
            @RequestParam(value = "id") int id,
            HttpSession session
            ){

        UserBean user = (UserBean)session.getAttribute("user");

        if(user == null) {
            return new ResponseEntity<>(false, HttpStatus.UNAUTHORIZED);
        }

        Optional<CommentBean> optionalComment = commentRepo.findById(id);

        if(optionalComment.isPresent()) {

            CommentBean comment = optionalComment.get();

            if(comment.getUser().getId() == user.getId()) {
                commentRepo.delete(comment);

                return new ResponseEntity<>(true, HttpStatus.OK);
            }else {
                return new ResponseEntity<>(false, HttpStatus.I_AM_A_TEAPOT);
            }

        }else {
            return new ResponseEntity<>(false, HttpStatus.NOT_FOUND);
        }       
    }   
}

lo

您缺少中的security依赖项pom.xml将以下内容添加到您的pom.xml更新Maven项目中。它应该解决依赖性。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

“导入org.springframework无法解析。”

导入org.springframework.boot.autoconfigure.web.ErrorAttributes无法解析

导入org.springframework.data无法在gradle中解析

导入org.springframework.web无法解析。蚀

无法导入org.springframework.test.context.ActiveProfiles;

无法导入 org.springframework.web.multipart.MultipartFile;

无法导入org.springframework.data.rest.webmvc.ResourceNotFoundException;

导入org.springframework.test.context.junit4.SpringJUnit4ClassRunner无法解析

org.springframework无法在karaf中解析

无法解析 org.springframework.security.core.GrantedAuthority 即使它已下载/显示在项目库下

设置bean属性'sourceList'时无法解析对bean'org.springframework.security.web.DefaultSecurityFilterChain#0'的引用

无法解析org.springframework.security.authentication.AuthenticationManager类型。从所需的.class文件间接引用它

无法导入springframework.security.extensions并找到saml()方法

使用键[0]设置bean属性“ sourceList”时,无法解析对bean'org.springframework.security.web.DefaultSecurityFilterChain#0'的引用

无法导入 org.springframework.web.bind.annotation.RestController;不能使用@Restcontroller

org.springframework.batch.item.excel.poi.PoiItemReader无法解析

import org.springframework.web.bind.annotation.DeleteMapping 无法解析

无法解析org.springframework.context.support.GenericApplicationContext类型

为什么org.springframework.boot不能导入,而org.springframework.web可以导入?

无法读取HTTP消息:org.springframework.http.converter.HttpMessageNotReadableException:JSON解析错误:无法构造实例

无法自动连线栏位:专用org.springframework.security.crypto.password.PasswordEncoder;

无法自动连线栏位:私人org.springframework.security.authentication.AuthenticationManager

java.lang.ClassCastException:类org.springframework.security.core.userdetails.User无法转换为class

Spring Security-无法找到:org.springframework.ldap.core.support.BaseLdapPathContextSource

org.springframework.security.core.userdetails.User无法转换为MyUserDetails

添加spring-security-oauth2后无法实例化接口org.springframework.context.ApplicationListener

无法找到 'org.springframework.security.oauth2.client.registration.ClientRegistrationRepository' 类型的 Bean。- 春季安全

org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.ui.Model]:指定的类是接口

org.springframework.web.multipart.commons.CommonsMultipartFile无法转换为org.springframework.web.multipart.MultipartFile