spring-randomport

spring RandomPort property source

License

License

Categories

Categories

Github Development Tools Version Controls
GroupId

GroupId

io.github.vlad-mk
ArtifactId

ArtifactId

io.github.vlad-mk.spring-randomport
Last Version

Last Version

0.1.4
Release Date

Release Date

Type

Type

jar
Description

Description

spring-randomport
spring RandomPort property source
Project URL

Project URL

https://github.com/vlad-mk/spring-randomport
Source Code Management

Source Code Management

https://github.com/vlad-mk/spring-randomport

Download io.github.vlad-mk.spring-randomport

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.vlad-mk/io.github.vlad-mk.spring-randomport/ -->
<dependency>
    <groupId>io.github.vlad-mk</groupId>
    <artifactId>io.github.vlad-mk.spring-randomport</artifactId>
    <version>0.1.4</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.vlad-mk/io.github.vlad-mk.spring-randomport/
implementation 'io.github.vlad-mk:io.github.vlad-mk.spring-randomport:0.1.4'
// https://jarcasting.com/artifacts/io.github.vlad-mk/io.github.vlad-mk.spring-randomport/
implementation ("io.github.vlad-mk:io.github.vlad-mk.spring-randomport:0.1.4")
'io.github.vlad-mk:io.github.vlad-mk.spring-randomport:jar:0.1.4'
<dependency org="io.github.vlad-mk" name="io.github.vlad-mk.spring-randomport" rev="0.1.4">
  <artifact name="io.github.vlad-mk.spring-randomport" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.vlad-mk', module='io.github.vlad-mk.spring-randomport', version='0.1.4')
)
libraryDependencies += "io.github.vlad-mk" % "io.github.vlad-mk.spring-randomport" % "0.1.4"
[io.github.vlad-mk/io.github.vlad-mk.spring-randomport "0.1.4"]

Dependencies

compile (1)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.21

test (6)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter jar 1.5.2.RELEASE
org.springframework.boot : spring-boot-starter-log4j2 jar 1.5.2.RELEASE
org.springframework.boot : spring-boot-test jar 1.5.2.RELEASE
org.springframework : spring-test jar 4.3.7.RELEASE
org.cthul : cthul-matchers jar 1.1.0
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Build Status

spring-randomport

Overview

Implements random port property source in spring, usually for test purposes. Takes a random available TCP port number an assign it to a corresponding property.

The PropertySource will be loaded automatically by spring-boot, if the library is in a class path.

In plain old spring a "io.github.vladmk.randomport" package have to be added to a @ComponentScan or @PropertySource(..., factory = RandomPortPrepertyFactory.class) can be used instead.

Property file example:

my.port=${randomport.my.port}

Boot example:

@RunWith(SpringRunner.class)
@SpringBootTest
public class MyTest {

    @Value("${randomport.xxx}")
    String port;

    .................
}

Spring example:

@Configuration
@ComponentScan(basePackages = "io.github.vladmk.randomport")
public class MyTestConfig {
}

@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {MyTestConfig.class})
public class MyTest {
    @Value("${randomport.xxx}")
    String port;

    ............

}

or

@Configuration
@PropertySource(value="dummy", factory = RandomPortPrepertyFactory.class,  ignoreResourceNotFound=true)
@ComponentScan
public class MyConfig {

   @Value("${randomport.xxx}")
    String port;

}

dependencies

testCompile group: 'io.github.vlad-mk', name: 'spring-randomport' ,  version: '0.1.7'

Versions

Version
0.1.4