在Spring Boot中使用@CrossOrigin

weixin_38054042 2019-09-12 01:00:37
我正在使用最新的Spring Boot(1.2.7.RELEASE).我想使用org.springframework.web.bind.annotation包中的@CrossOrigin注释,如Spring文档中的CORS Support部分所述. 我认为我已经拥有了所有必要的依赖项(通过Spring Boot默认值),但这很令人困惑:找不到CrossOrigin,即使像同一个程序包中的RestController这样的东西也可以工作! Error:(8, 47) java: cannot find symbol symbol: class CrossOrigin location: package org.springframework.web.bind.annotation 这是怎么回事? CrossOrigin是否已从更高版本的Spring-MVC中删除,还是我错过了一些依赖? pom.xml中: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.2.7.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
...全文
685 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38061732 2019-09-12
  • 打赏
  • 举报
回复
好吧,看起来像最新的Spring Boot版本,1.2.7.RELEASE目前,太老了,不能有一个带有CrossOrigin的Spring MVC版本. (Spring Boot 1.2.7 uses Spring version 4.1.8). 我更新到最新的Spring Boot 1.3发布候选版本(1.3.0.RC1)并且它可以工作: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.0.RC1</version> </parent> 还需要在pom.xml中指定spring-milestones存储库才能使用非发行版本. <repositories> <repository> <id>spring-milestones</id> <url>http://repo.spring.io/milestone</url> </repository> </repositories> 更新:覆盖Spring版本 正如StéphaneNic​​oll指出的那样,使用Spring 4.2.2类(例如CrossOrigin)的一种更简单的方法是: <properties> <!-- ... --> <spring.version>4.2.2.RELEASE</spring.version> </properties>

477

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧