首页 > 解决方案 > 为什么我不能在我的 Eclipse Maven 项目中将一个类导入到我的 java 文件中?

问题描述

我在Maven 存储库中找到了以下内容:

<!-- https://mvnrepository.com/artifact/org.springframework.xd/spring-xd-dirt -->
<dependency>
    <groupId>org.springframework.xd</groupId>
    <artifactId>spring-xd-dirt</artifactId>
    <version>1.0.4.RELEASE</version>
</dependency>

Maven Repository 提供的主页将我带到这个 java 文件

这里是:

/*
 * Copyright 2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.xd.dirt.web.controller.support;

/**
 *
 * @author Gunnar Hillert
 *
 */
public class AuthenticationRequest {

    private String username;

    private String password;

    public AuthenticationRequest() {
    }

    public AuthenticationRequest(String username, String password) {
        this.username = username;
        this.password = password;
    }

    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }

    /**
     * @param username the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return "AuthenticationRequest [username=" + username + ", password=" + password + "]";
    }


}

该页面告诉我可以使用 AuthenticationRequest 导入

import org.springframework.xd.dirt.web.controller.support.AuthenticationRequest;

我在 pom.xml 中收到一个错误,说缺少工件。我想该库依赖于另一个库。我将工件放在 pom.xml 中,该错误已解决。

但是我的导入语句仍然出现错误,说:

导入 org.springframework.xd.dirt.web.controller.support 无法解决

我错过了什么?如何导入类 AuthenticationRequest?

标签: javaspringeclipsemavenimport

解决方案


我做了一些搜索,发现我需要在我的 pom.xml 中包含以下内容:

    <dependency>
        <groupId>org.springframework.xd</groupId>
        <artifactId>spring-xd-dirt</artifactId>
        <!-- <version>1.0.4.RELEASE</version> -->
        <version>1.3.1.RELEASE</version>
        <!-- <scope>compile</scope> -->
    </dependency>

    <repository>
        <id>spring-repo</id>
        <url>https://repo.spring.io/release</url>
    </repository>

推荐阅读