Skip to content

Adding netty dependency to classpath breaks root uri generation #9605

@kewne

Description

@kewne

With this controller:

//  MyController.java

@RestController
@SpringBootApplication
public class MyController {

    @PostMapping("/hello")
    public ResponseEntity<?> fakePost() {
        return ResponseEntity.created(
                fromMethodCall(MvcUriComponentsBuilder.on(MyController.class).fakePost())
                        .build()
                        .toUri())
                .build();
    }

}

And this build.gradle script:

// build.gradle
buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.4.RELEASE")
    }
}
group 'spring-repro'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'org.springframework.boot'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile('org.springframework.boot:spring-boot-starter-test')
    // uncomment this to break the test
//    testCompile 'io.netty:netty-all:4.1.12.Final'
}

Adding the netty dependency breaks this test:

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@RunWith(SpringRunner.class)
public class MyControllerTest {

    @Autowired
    private TestRestTemplate testRestTemplate;

    @LocalServerPort
    private int port;

    @Test
    public void test() {
        RequestEntity<Void> request = RequestEntity.post(URI.create("/hello"))
                .build();
        ResponseEntity<Void> exchange = testRestTemplate.exchange(request, Void.class);
        URI location = exchange.getHeaders().getLocation();
        assertEquals(port, location.getPort());
        /*
             java.lang.AssertionError: 
             Expected :49676
             Actual   :-1
        */
    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions