Maven pom.xml Spring Boot不存在

时间:2018-03-07 07:49:52

标签: java spring maven spring-boot

我是java世界的新手。我有这个错误"包org.springframework.boot不存在"在我的SpringApplication Runner类上。但是我将Spring Boot依赖项添加到pom.xml中 我不明白为什么我得到这个错误。

pom.xml

    <dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>javax.transaction-api</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

userDAO的

    @Repository
public class UsersDao {

    @PersistenceContext
    private EntityManager entityManager;

    public void save(Users users){
        entityManager.persist(users);
    }

}

UserDTO

public class UsersDto {

private Integer id;
private String name;
private String surname;
private String username;
private Boolean isSuperUser;
private String email;
private String password;
private Date created_at;
private Date updated_at;


public UsersDto(){

}

public UsersDto(Users users){
    this.id = users.getId();
    this.name = users.getName();
    this.surname = users.getSurname();
    this.email = users.getEmail();
    this.isSuperUser = users.getSuperUser();
    this.username = users.getUsername();
    this.password = users.getPassword();
}//AND GETTER&SETTER

UserResources

    @Component
@Path("/users")
public class UsersResources {
    @Autowired
    UsersService usersService;

    @POST
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Response saveCity(UsersDto usersDto){
        Users users;

        try{
            users = usersService.saveUsers(usersDto);

        }catch (Exception e){
            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
        }
        return Response.ok(users).build();
    }

}

和UserServices

    @Service
public class UsersService {

    @Autowired
    private UsersDao usersDao;

    @Transactional
    public Users saveUsers(UsersDto usersDto){

        Users users = new Users();
        users.setName(usersDto.getName());
        users.setEmail(usersDto.getEmail());
        users.setSuperUser(usersDto.getSuperUser());
        users.setSurname(usersDto.getSurname());
        users.setPassword(usersDto.getPassword());
        usersDao.save(users);

        return users;
    }

}

用户模型

@Entity
@Table(name="users")
public class Users implements Serializable {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="id")
    private Integer id;

    @Column(name="name")
    private String name;

    @Column(name="surname")
    private String surname;

    @Column(name="username")
    private String username;

    @Column(name="password")
    private String password;

    @Column(name="is_super_user")
    private Boolean isSuperUser;

    @Column(name="email")
    private String email;


    @Column(name="created_at")
    private Date created_at;

    @Column(name="updated_at")
    private Date updated_at;


    @PrePersist
    protected void onCreate() {
        created_at = new Date();
    }

    @PreUpdate
    protected void onUpdate() {
        updated_at = new Date();
    }

我的错在哪里?我该如何解决?我想问类似的问题。有时我们会遇到一些错误但我找不到它。所以我们理解这个错误的原因就是pom。 xml依赖冲突。但没有错误maven.We因为不兼容的依赖而感到疲倦。有任何防止依赖冲突的解决方案吗?(如maven依赖验证器)

2 个答案:

答案 0 :(得分:2)

使用Spring Initilia更简单的方法是使用Spring Initiliazr https://start.spring.io/创建Spring Boot项目。您可以从这里创建一个maven项目,该项目具有Spring Boot或更多其他依赖项,并且已经修补。

答案 1 :(得分:0)

如果您刚刚开始为什么不使用https://start.spring.io/生成项目。

您添加了核心Spring依赖项,但没有添加单个Spring Boot依赖项。您只有Spring Boot BOMparent,它们只管理<dependencyManagement>的依赖项。您可以通过运行mvn dependency:tree来检查您的依赖项。