Spring extension to load native libraries via jnr-ffi.
Tests are written for windows
dependencies {
compile group: 'com.github.goto1134', name: 'spring-jnr', version: '1.0'
}
<dependencies>
<dependency>
<groupId>com.github.goto1134</groupId>
<artifactId>spring-jnr</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
- Register
BeanPostProcessor
@Bean
public BeanPostProcessor nativeLibraryBeanPostProcessor() {
return new NativeLibraryBeanPostProcessor();
}
- Declare configuration qualifier
@Qualifier
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface MicrosoftVisualCRuntime {
}
- Declare library configuration
@MicrosoftVisualCRuntime
@Component
public class MicrosoftVisualCRuntimeConfiguration
implements NativeLibraryConfiguration {
@Override
public LibraryInfo getLibraryInfo() {
if (Platform.getNativePlatform()
.getOS() != Platform.OS.WINDOWS) {
throw new IllegalStateException("Must be windows OS");
}
return new LibraryInfo("msvcrt", "", CallingConvention.STDCALL, true, IdentityFunctionMapper.getInstance());
}
}
- Mark all libraries with the same qualifier
@MicrosoftVisualCRuntime
public interface PseudoRandomSequenceGenerator {
int rand();
}
- Mark all fields where injection is needed
@NativeLibrary
private PseudoRandomSequenceGenerator generator;