gpt4 book ai didi

java - Spring Boot Maven pom.xml 不存在

转载 作者:行者123 更新时间:2023-12-02 02:17:13 26 4
gpt4 key购买 nike

我是 java 世界的新手。我的 SpringApplication Runner 类上出现此错误“package org.springframework.boot 不存在”。但是我将 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>

用户Dao

    @Repository
public class UsersDao {

@PersistenceContext
private EntityManager entityManager;

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

}

用户DTO

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

用户资源

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

}

和用户服务

    @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 上的错误。由于不兼容的依赖关系,我们很累。有没有防止依赖冲突的解决方案?(如 maven 依赖 validator )

最佳答案

要使用 Spring Boot,更简单的方法是使用 Spring Initiliazr https://start.spring.io/ 创建 Spring Boot 项目。 。您可以从这里创建一个 Maven 项目,其中已修补了 Spring Boot 或更多其他依赖项。

关于java - Spring Boot Maven pom.xml 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49146685/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com