SpringBoot包不存在

yacmzcpb  于 2024-01-06  发布在  Spring
关注(0)|答案(1)|浏览(195)

在Springboot中开始,下面的包找不到。我已经添加了两个依赖项,单击Maven并重新加载项目,并尝试重建项目,但仍然没有成功。可能是一个简单的修复。

  1. import javax.persistence.Entity;
  2. import javax.persistence.GeneratedValue;
  3. import javax.persistence.GenerationType;
  4. import javax.persistence.Id;
  5. @Entity
  6. public class ExampleEntity {
  7. @Id
  8. @GeneratedValue(strategy = GenerationType.IDENTITY)
  9. private Long id;
  10. private String name;
  11. }

字符串
下面是我的pom.xml:

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-thymeleaf</artifactId>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.springframework.boot</groupId>
  8. <artifactId>spring-boot-starter-web</artifactId>
  9. </dependency>
  10. <dependency>
  11. <groupId>org.springframework.boot</groupId>
  12. <artifactId>spring-boot-starter-test</artifactId>
  13. <scope>test</scope>
  14. </dependency>
  15. <dependency>
  16. <groupId>org.springframework.boot</groupId>
  17. <artifactId>spring-boot-starter-data-jpa</artifactId>
  18. </dependency>
  19. <!-- H2 Database -->
  20. <dependency>
  21. <groupId>com.h2database</groupId>
  22. <artifactId>h2</artifactId>
  23. <scope>runtime</scope>
  24. </dependency>
  25. </dependencies>
  26. <build>
  27. <plugins>
  28. <plugin>
  29. <groupId>org.springframework.boot</groupId>
  30. <artifactId>spring-boot-maven-plugin</artifactId>
  31. </plugin>
  32. </plugins>
  33. </build>
  34. </project>

r1zhe5dt

r1zhe5dt1#

很可能是javax导入的问题。spring,jpa和许多其他spring模块的最新版本已经迁移到了jakaltar命名空间。这意味着除非你想专门使用旧版本的依赖项,否则大多数(但不是全部)javax导入和依赖项都需要更改为jakaltar。
https://spring.io/blog/2021/09/02/a-java-17-and-jakarta-ee-9-baseline-for-spring-framework-6

相关问题