Tag: 春天

如何在后端获取用户国家的HTTP请求?

我试图让用户发送请求到我的服务器的国家。 到目前为止,我找到了这些解决方案 https://github.com/fiorix/freegeoip https://github.com/maxmind/GeoIP2-java 这些解决方案是使用MaxMind数据库GeoIP2国家数据库,它有一个许可证,对于这个特定的项目我有图书馆的限制(法律方面因为业务) 我发现一些话题提到Google API可以提供这个服务,但是我在Java或Kotlin上找不到任何最终的东西。 有人知道一个解决方案不同于所提到的(在后端运行)吗?

使用Aspect将响应标题添加到所有控制器

我希望我所有的Spring MVC控制器都包含一些常见的响应头文件。 我可以使用以下(Kotlin)做到这一点: @ModelAttribute open fun responseHeaders(response: HttpServletResponse) { //identify the node that serviced the call response.setHeader("host-name", InetAddress.getLocalHost().hostName); //etc } 。 。 因为它适用于所有,我可以使用基类。 但是,有没有建议的方式来使用一个方面?

相同的其他端点具有不同的PathVariable

我试图做两个相同的uri,但不同类型的休息端点。 第一个将通过EAN(Int)进行搜索,第二个将通过id(String)进行搜索。 我能否以某种方式超载端点? 我和Kotlin一起使用Spring Boot @GetMapping("/book/{ean}") fun getABookByEan(@PathVariable ean: Int) : ResponseEntity<*> { repository.getByEan(ean)?.let { return ResponseEntity.status(HttpStatus.OK).body(it) } throw ItemNotFoundException() } @GetMapping("/book/{id}") fun getABookById(@PathVariable id: String) : ResponseEntity<*> { repository.getById(id)?.let { return ResponseEntity.status(HttpStatus.OK).body(it) } throw ItemNotFoundException() } 在此之后,我得到了一个异常,多个方法被映射为相同的端点。 NestedServletException:请求处理失败; 嵌套异常是java.lang.IllegalStateException:为HTTP路径映射的模糊处理程序方法…

Spring Boot 2&Spring 5错误服务index.html

我有一个简单的Spring启动应用程序写在Kotlin。 @SpringBootApplication class DemoApplication fun main(args: Array<String>) { SpringApplication.run(DemoApplication::class.java, *args) } @Controller class HomeController { @GetMapping("/") fun home() = "index.html" } 在resource/public文件夹我有index.html 。 但是,当我打开我的浏览器并键入localhost:8080/我得到了错误java.lang.IllegalStateException: Could not resolve view with name 'index.html'在运行的Spring启动控制台java.lang.IllegalStateException: Could not resolve view with name 'index.html' 。 我只想要最简单的代码possbile服务于index.html。 不应该那么辛苦? ;) 注意:我正在使用Spring-Web-Reactive

什么是开放的财产? 为什么我不能让自己的私人?

Kotlin的房地产和开放式房产之间有什么区别? 下面的代码抱怨我声明setter 私有和Intellij说私人 setter不允许打开属性。 什么是开放的财产? @RestController open class ParameterController { @Autowired lateinit var parameterRepository: ParameterRepository private set //error } 为什么上面的代码无效,但是这个代码是? open class ItemPrice{ lateinit var type: String private set // ok } 编辑:我使用spring-allopen插件,并明确标记类作为打开没有区别。

Spring的Facebook模板映射fetchObject到PagedList

我正在使用以下方法来返回Facebook用户的音乐首选项: //FIXME: Fetch results in a single operation val likes = facebook.likeOperations().music val artists = ArrayList<Artist>() for (musicLiked in likes) { val musicProfile = facebook.fetchObject(musicLiked.id, Page::class.java, "id", "name", "genre"); artists.add(Artist(name = musicProfile.name, genre = musicProfile.genre)) } 上述方法不会缩放,因为我们对每个用户喜欢的艺术家都有一个额外的网络操作。 我试过了: 我试图使用facebook.likeOperations.music但是这不会获取流派。 题: 我想用facebook.fetchObject与返回一个PagedList的查询。 如何做到这一点? (如果您愿意或者对Java更熟悉,不需要在Kotlin中发布示例代码 – 我将很乐意使用任何语言的信息) 。

异常处理程序不能使用`spring-boot-starter-data-rest`

我最后一次Java / Spring的经验大约在四年前。 我开始用Kotlin学习Spring Boot。 我已经创建了一个像这样的RESTful Web服务(在Kotlin中),它工作正常: @RequestMapping("/authorization") public fun authorization(@RequestParam(value = "network-type", defaultValue = "Facebook") name: String, @RequestParam(value = "oauth-token") oauthToken: String, @RequestParam(value = "oauth-token-secret", required = false) oauthTokenSecret: String?): Authorization { //TODO: Handle other social network types return facebookAuth.authorization(oauthToken) } 现在我无法添加一个异常处理程序,当facebookAuth抛出UnauthorizedException。 我试过了: 我试图在控制器上注册一个异常处理程序方法。 我试过用@ControllerAdvice创建交叉异常顾问类 在这两种情况下,异常都没有映射,而是我得到: 白标签错误页面 此应用程序没有明确的映射/错误,所以你看到这是一个后备。 Sun Oct 25 16:00:43 PHT 2015 […]

不能使用MongoDB的spring验证

我在Kotlin寻找了在春季验证数据模型的解决方案。 但我不能。 以下是标签data class 。 data class Tag(@field:NotNull var name: String) { lateinit @Id var id: ObjectId } 我已经启用配置来使用bean验证 @Configuration open class ValidatorConfig { @Bean open fun validator() = LocalValidatorFactoryBean() } 据我所知,Spring Boot会自动加载所有的Bean配置。 在运行时,当用空的Json POST时,应该抛出适当的验证错误,但会抛出以下错误 Instantiation of [simple type, class kagaz.sano.model.Tag] value failed for JSON property name due to missing (therefore NULL) value for creator […]

IntelliJ社区找不到Web应用程序工件来生成WAR

我正在使用IntelliJ-IDEA Community Edition从Maven-Project生成一个war文件。 当谈到生成这个战争文件我找不到工件之间的战争选项。 我试图: 1)转到文件>项目结构>工件>类型 ,但未提及WAR; 2)右键单击项目模块>添加框架支持 ,但没有提到Web应用程序 (我只有Groovy,Kotlin(Java),Kotlin(JavaScript)。 这是我的pom.xml文件: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>mawashi.alex.firstapp</groupId> <artifactId>firstapp</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>firstapp</name> <url>http://maven.apache.org</url> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.2.7.RELEASE</version> </parent> <properties> <java.version>1.8</java.version> </properties> <dependencies> <!–automatic configuration for web applications–> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <version>1.4.1.RELEASE</version> <scope>provided</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> […]

Spring WebFlux:Reactive MongoDB

我是Spring Reactor的新手,所以我想重构这个简单的spring数据(在kotlin)方法: fun save(user: User): Mono<User> { if (findByEmail(user.email).block() != null) { throw UserAlreadyExistsException() } user.password = passwordEncoder.encode(user.password) return userRepository.save(user) } 谢谢