JNDI here refers to Java to .Net Interface, not Java Naming and Directory Interface.
Java to .Net Interface based on Spring Boot. Call managed DLL using Javonet or Jacob as the driver. Native DLL (Unmanaged DLL) are not supported.
- support DLL lib
- support SO lib
- support Javonet Driver
- support Jacob Driver
- suppor JCOBridge Driver
- support JNA Driver
- custom selection .Net framework (currently only 4.0 is supported)
- support more javanet authentication methods
- Maven
// not yet
Currently only supported Javonet Driver.
Add @EnableJdni
annotation on startup application, and you can enter the driver()
value to select the JDNI driver, default use Javonet driver.
@EnableJdni(driver = DriverType.JAVONET)
public class MyApplication
- Simplest interface class
Build interface class, the name corresponds to the .Net type name. Write .Net mapping interface, method name must be corresponds to the .Net method. Method parameter names do not have to correspond, only the same count, but pay attention to the type.
Most importantly add @DotNetFunction
annotation on your interface. Modify the annotation @EnableJdni(basePackage = {})
to select the package to be scanned.
@DotNetFunction
public interface DotNetTypeName {
String DotNetMethod(String arg0, int arg1);
}
- Use default configuration class
The default config class supports configuration in the form of properties file, the following is an example of yaml.
jdni:
lib:
- "System.IO"
- "D:\\MyLib.dll"
javonet-email: ${javonet.email}
javonet-license: ${javonet.license}
- Implement JdniConfig and inject into spring container
The JdniConfig implementation class will be used in the JdniConfigProcessor class.
@Configration
public class MyJdniConfig implements JdniConfig {
@Override
public Properties initProperties(DriverType driverType) {
// returned here will be used by JdniDriver.init(Properties)
}
@Override
public String[] loadLibrary() {
// returned here will be used by JdniDriver.loadLibrary(Path...)
}
}
-
@DotNetFunction
- The
typeName
property is the mapped .Net type name, if not set, it defaults to the interface name of the annotation. isStatic
is set to true, the .Net object will not be instantiated.- The
constructor
property sets the class that can return the parameters required by the constructor, which must be constructed without parameters or injected into the Spring Boot container.
- The
-
@DotNetMethod
- The
name
property is the mapping .Net method name, if not set, it defaults to the interface method name. typeHandler
sets the method return type handler, which specifically handles the value returned by the JNDI driver.
- The
@DotNetFunction
public interface DotNetTypeName {
// normal return Integer
Integer DotNetMethod();
// is processed as String
@DotNetMethod(typeHandler = MyTypeHandler.class)
String DotNetMethod();
}
public class MyTypeHandler implements JdniTypeHandler {
@Override
public Object process(Object obj) {
return String.valueOf(obj);
}
}
- @DotNetParam
typeHandler
is different from@DotNetMethod
, this handles input parameters.