I am trying to add a Coap server through Eclipse Californium in a Java Spring boot-based application. Below are the codes.
import org.eclipse.californium.core.CoapServer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class CoapServerConfiguration {
@Bean
public CoapServer coapServer() {
int portNumber = 9995;
CoapServer coapServer= null;
try {
coapServer = new CoapServer(portNumber);
coapServer.add();
}catch(Exception e) {e.printStackTrace();}
// Add your CoAP resources here
// server.add(new YourCoapResource());
// System.out.println("Coap server started");
return coapServer;
}
}
However, when I start the application, I get the following error.
java.lang.IllegalStateException: Configuration contains no definitions!
at org.eclipse.californium.elements.config.Configuration.add(Configuration.java:802)
at org.eclipse.californium.elements.config.Configuration.load(Configuration.java:772)
at org.eclipse.californium.elements.config.Configuration.load(Configuration.java:738)
at org.eclipse.californium.elements.config.Configuration.createWithFile(Configuration.java:628)
at org.eclipse.californium.elements.config.Configuration.createStandardWithFile(Configuration.java:588)
at org.eclipse.californium.elements.config.Configuration.getStandard(Configuration.java:458)
at org.eclipse.californium.core.CoapServer.<init>(CoapServer.java:184)
at com.dropbydrop.smartmeter.CoapServerConfiguration.coapServer(CoapServerConfiguration.java:16)
I have added the following dependencies also,in this application.
<dependency>
<groupId>org.eclipse.californium</groupId>
<artifactId>californium-core</artifactId>
<version>3.9.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.californium/element-connector -->
<dependency>
<groupId>org.eclipse.californium</groupId>
<artifactId>element-connector</artifactId>
<version>3.9.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.californium/californium-legal -->
<dependency>
<groupId>org.eclipse.californium</groupId>
<artifactId>californium-legal</artifactId>
<version>3.9.0</version>
<scope>runtime</scope>
</dependency>
Starting with Californium 3.0, the configuration uses modules. Before using the configuration, the required modules must be registered. See Config.register()