Cannot resolve symbol ‘security’ while importing io.jsonwebtoken.security.Keys;

huangapple go评论114阅读模式
英文:

Cannot resolve symbol 'security' while importing io.jsonwebtoken.security.Keys;

问题

以下是翻译好的部分:

我尝试构建一个关于使用JWT进行API身份验证的项目。我已经安装了版本为0.9.1的io.jsonwebtoken软件包来实现这一目标。

我的pom.xml文件如下:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>2.3.4.RELEASE</version>
  9. <relativePath/> <!-- lookup parent from repository -->
  10. </parent>
  11. <groupId>com.xyz</groupId>
  12. <artifactId>jwt_api_authentication</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <name>jwt_api_authentication</name>
  15. <description>Demo project for Spring Boot</description>
  16. <properties>
  17. <java.version>1.8</java.version>
  18. </properties>
  19. <dependencies>
  20. <dependency>
  21. <groupId>org.springframework.boot</groupId>
  22. <artifactId>spring-boot-starter-data-jpa</artifactId>
  23. </dependency>
  24. <dependency>
  25. <groupId>org.springframework.boot</groupId>
  26. <artifactId>spring-boot-starter-web</artifactId>
  27. </dependency>
  28. <dependency>
  29. <groupId>org.springframework.boot</groupId>
  30. <artifactId>spring-boot-starter-security</artifactId>
  31. </dependency>
  32. <dependency>
  33. <groupId>org.springframework.security</groupId>
  34. <artifactId>spring-security-test</artifactId>
  35. <scope>test</scope>
  36. </dependency>
  37. <dependency>
  38. <groupId>org.springframework.boot</groupId>
  39. <artifactId>spring-boot-devtools</artifactId>
  40. <scope>runtime</scope>
  41. <optional>true</optional>
  42. </dependency>
  43. <dependency>
  44. <groupId>mysql</groupId>
  45. <artifactId>mysql-connector-java</artifactId>
  46. <scope>runtime</scope>
  47. </dependency>
  48. <dependency>
  49. <groupId>org.springframework.boot</groupId>
  50. <artifactId>spring-boot-starter-test</artifactId>
  51. <scope>test</scope>
  52. <exclusions>
  53. <exclusion>
  54. <groupId>org.junit.vintage</groupId>
  55. <artifactId>junit-vintage-engine</artifactId>
  56. </exclusion>
  57. </exclusions>
  58. </dependency>
  59. <dependency>
  60. <!-- JSON Web Token Support -->
  61. <groupId>io.jsonwebtoken</groupId>
  62. <artifactId>jjwt</artifactId>
  63. <version>0.9.1</version>
  64. </dependency>
  65. </dependencies>
  66. <build>
  67. <plugins>
  68. <plugin>
  69. <groupId>org.springframework.boot</groupId>
  70. <artifactId>spring-boot-maven-plugin</artifactId>
  71. </plugin>
  72. </plugins>
  73. </build>
  74. </project>

当我尝试导入"io.jsonwebtoken.security.Keys"时,我遇到了这个错误:"无法解析符号'security'"。

我尝试了0.6.0版本,但仍然没有成功。

我该如何修复这个问题呢?谢谢。

英文:

I was trying to build a project about API authentication using JWT. I have installed the io.jsonwebtoken package with version 0.9.1 in order to do that.

My pom.xml

  1. &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  2. &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
  3. xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  4. &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  5. &lt;parent&gt;
  6. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  7. &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
  8. &lt;version&gt;2.3.4.RELEASE&lt;/version&gt;
  9. &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
  10. &lt;/parent&gt;
  11. &lt;groupId&gt;com.xyz&lt;/groupId&gt;
  12. &lt;artifactId&gt;jwt_api_authentication&lt;/artifactId&gt;
  13. &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  14. &lt;name&gt;jwt_api_authentication&lt;/name&gt;
  15. &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  16. &lt;properties&gt;
  17. &lt;java.version&gt;1.8&lt;/java.version&gt;
  18. &lt;/properties&gt;
  19. &lt;dependencies&gt;
  20. &lt;dependency&gt;
  21. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  22. &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
  23. &lt;/dependency&gt;
  24. &lt;dependency&gt;
  25. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  26. &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
  27. &lt;/dependency&gt;
  28. &lt;dependency&gt;
  29. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  30. &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
  31. &lt;/dependency&gt;
  32. &lt;dependency&gt;
  33. &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
  34. &lt;artifactId&gt;spring-security-test&lt;/artifactId&gt;
  35. &lt;scope&gt;test&lt;/scope&gt;
  36. &lt;/dependency&gt;
  37. &lt;dependency&gt;
  38. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  39. &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
  40. &lt;scope&gt;runtime&lt;/scope&gt;
  41. &lt;optional&gt;true&lt;/optional&gt;
  42. &lt;/dependency&gt;
  43. &lt;dependency&gt;
  44. &lt;groupId&gt;mysql&lt;/groupId&gt;
  45. &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
  46. &lt;scope&gt;runtime&lt;/scope&gt;
  47. &lt;/dependency&gt;
  48. &lt;dependency&gt;
  49. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  50. &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
  51. &lt;scope&gt;test&lt;/scope&gt;
  52. &lt;exclusions&gt;
  53. &lt;exclusion&gt;
  54. &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
  55. &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
  56. &lt;/exclusion&gt;
  57. &lt;/exclusions&gt;
  58. &lt;/dependency&gt;
  59. &lt;dependency&gt;
  60. &lt;!-- JSON Web Token Support --&gt;
  61. &lt;groupId&gt;io.jsonwebtoken&lt;/groupId&gt;
  62. &lt;artifactId&gt;jjwt&lt;/artifactId&gt;
  63. &lt;version&gt;0.9.1&lt;/version&gt;
  64. &lt;/dependency&gt;
  65. &lt;/dependencies&gt;
  66. &lt;build&gt;
  67. &lt;plugins&gt;
  68. &lt;plugin&gt;
  69. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  70. &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
  71. &lt;/plugin&gt;
  72. &lt;/plugins&gt;
  73. &lt;/build&gt;
  74. &lt;/project&gt;

While I'm trying to import "io.jsonwebtoken.security.Keys" I'm getting this error: "Cannot resolve symbol 'security'".

I tried 0.6.0 but still no luck.

How can I fix this?
Thanks.

答案1

得分: 11

我在我的pom.xml配置文件中有以下内容。这对我起作用了。我移除了问题中的那个依赖,并替换为以下内容。

  1. <dependency>
  2. <groupId>io.jsonwebtoken</groupId>
  3. <artifactId>jjwt-impl</artifactId>
  4. <version>0.11.5</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>io.jsonwebtoken</groupId>
  8. <artifactId>jjwt-api</artifactId>
  9. <version>0.11.5</version>
  10. </dependency>
  11. <dependency>
  12. <groupId>io.jsonwebtoken</groupId>
  13. <artifactId>jjwt-jackson</artifactId>
  14. <version>0.11.5</version>
  15. </dependency>

编辑:2023年1月27日

将答案中先前版本0.11.1的库更新为最新版本0.11.5。

英文:

I have this configuration in my pom.xml. This worked for me. I removed the dependency as you have in the question and replaced it with below.

  1. &lt;dependency&gt;
  2. &lt;groupId&gt;io.jsonwebtoken&lt;/groupId&gt;
  3. &lt;artifactId&gt;jjwt-impl&lt;/artifactId&gt;
  4. &lt;version&gt;0.11.5&lt;/version&gt;
  5. &lt;/dependency&gt;
  6. &lt;dependency&gt;
  7. &lt;groupId&gt;io.jsonwebtoken&lt;/groupId&gt;
  8. &lt;artifactId&gt;jjwt-api&lt;/artifactId&gt;
  9. &lt;version&gt;0.11.5&lt;/version&gt;
  10. &lt;/dependency&gt;
  11. &lt;dependency&gt;
  12. &lt;groupId&gt;io.jsonwebtoken&lt;/groupId&gt;
  13. &lt;artifactId&gt;jjwt-jackson&lt;/artifactId&gt;
  14. &lt;version&gt;0.11.5&lt;/version&gt;
  15. &lt;/dependency&gt;

<b>Edit: 27 Jan 2023</b>

Updated versions of the libs to the latest version 0.11.5 from earlier 0.11.1 in the answer.

答案2

得分: 5

基于 https://search.maven.org/search?q=fc:io.jsonwebtoken.security.Keys%20AND%20g:io.jsonwebtoken(这是您可以获取包含特定类的特定 groupId 的工件列表的方法),您至少需要 0.10.0 版本的 jjwt-api。

英文:

Based on https://search.maven.org/search?q=fc:io.jsonwebtoken.security.Keys%20AND%20g:io.jsonwebtoken (this is how you can get the list of artifacts with a specific groupId containing a specific class), you need at least 0.10.0 ofjjwt-api

huangapple
  • 本文由 发表于 2020年10月18日 22:40:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/64414584.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定