春ブーツ(webflux)残りのコントローラのリモートIPアドレスを取得

user2914191:

シンプルなRESTアプリケーションの春ブーツを使用。

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

私は、そのハンドルのリクエストシンプルなコントローラを持っています。

@RestController
@RequestMapping("/api")
public class MainController {

    @RequestMapping("/test")
    public BasicDTO getBasic(HttpServletRequest request){
        System.out.println(request.getRemoteAddr());
        return new BasicDTO();
    }

}

HttpServletRequestコンテキストが注入されません。私はいくつかの基本的なソケットの詳細にアクセスできるように、どのように私は、メソッドに要求コンテキストを注入することができますか?ありがとうございました。

ベンジャミンC:

あなたを見てみるとpom.xml、それは使用していますspring-boot-starter-webfluxあなたが使用しなければならないので、ServerHttpRequest代わりのをHttpServletRequest

または含まれ、

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

および削除spring-boot-starter-webfluxの依存関係を。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=204459&siteId=1