Consider defining a bean of type 'com.cumulocity.sdk.client.inventory.InventoryApi' in your configuration

What product/components do you use and which version/fix level?

Cumulocity sdk

Are you using a free trial or a product with a customer license?

customer license

What are trying to achieve? Please describe in detail.

I am trying to compile one of the softwareag’s project that accesses InventoryApi, MeasurementApi. the GIT project is cumulocity-microservice-templates / basic But when I use one of the projects ‘basic’ under that am getting the following error while running. I need help to make it running and see the MeasurementApi accesing the measurements and create measurements also.

Error while running the application.is below


APPLICATION FAILED TO START


Description:

Parameter 0 of constructor in com.c8y.ms.templates.basic.service.DeviceService required a bean of type ‘com.cumulocity.sdk.client.inventory.InventoryApi’ that could not be found.

Action:

Consider defining a bean of type ‘com.cumulocity.sdk.client.inventory.InventoryApi’ in your configuration.

Do you get any error messages? Please provide a full error message screenshot and log file.

Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
2022-06-28 11:12:25.687 ERROR 2640 — [ main] o.s.b.d.LoggingFailureAnalysisReporter :


APPLICATION FAILED TO START


Description:

Parameter 0 of constructor in com.c8y.ms.templates.basic.service.DeviceService required a bean of type ‘com.cumulocity.sdk.client.inventory.InventoryApi’ that could not be found.

Action:

Consider defining a bean of type ‘com.cumulocity.sdk.client.inventory.InventoryApi’ in your configuration.

Have you installed latest fixes for the products

Hi Sethu,

i tested the basic template in the main branch. It was working for me. Could you please tell me how you started the .jar file, i mean the java -jar … command. Did you really use the cumulocity-microservice-templates-basic-0.0.1-SNAPSHOT.jar ? The exceptions shows that the cumulocity SDK classes are not in the class path. I could maybe imagin that you started: cumulocity-microservice-templates-basic-0.0.1-SNAPSHOT.jar.original

How did you build the jar? Did it fail?

Best regards,
Alex

Hi Alexander,
Thanks for replying. I am compiling it using mvn clean install and running it using mvn spring-boot:run by adding a server port in the application.properties file. I am trying to access the end point in my local.
I have taken only the basic project out of the parent project cumulocity-microservice-templates and trying to compile and run it as i said above.

Could you tell me how did you start the application?

Are you able to access the end points defined in DeviceController and MeasurmentController in that case?

when i run mvn clean install its a succes, when i use mvn spring-boot:run it throws the error that i have given in my question initially.

Regards,
P. Sethu pandia raja

What version of Java are you using?

Hi Robert
I tried with java 8 and 11 both

Did you edit the application-dev.properties? You have to add values to:
C8Y.bootstrap.tenant
C8Y.baseURL
C8Y.bootstrap.user
C8Y.bootstrap.password

mvn spring-boot:run was also working on my env

i am using java 11 and maven 3.6.3

I took out the “basic” project alone from the main project. So I had to make the following changes in pom.xml and application-dev.properties files. I have not done any other changes.
I have given and asked at some points in the properties file what needs to be filled. Kindly check below.

Trying to run mvn clean install - its buiding well. When I give mvn spring-boot:run it throws the error I have pasted at the last below.

pom.xml changes

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>11</java.version>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>

    <spring-boot-dependencies.version>2.5.4</spring-boot-dependencies.version>
    <c8y.version>1010.0.0</c8y.version>
    <c8y.docker.skip>true</c8y.docker.skip>
    <junit.version>4.13</junit.version>
</properties>


<repositories>
    <repository>
        <id>cumulocity</id>
        <layout>default</layout>
        <url>http://download.cumulocity.com/maven/repository</url>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>public</id>
        <url>http://download.cumulocity.com/maven/repository</url>
    </pluginRepository>
</pluginRepositories>

Commented out the plugin section that creates the image. So I thought to run it in the local port 8082 as given in the properties file below.

application-dev.properties file changes

#Do not edit, version properties are set at build time
c8y.version=@c8y.version@
microservice.version=@project.version@
server.port=8082

#Cumulocity configuration for running localy and connecting to cumulocity
application.name=templates-basic
C8Y.bootstrap.register=true
C8Y.bootstrap.tenant= ??? what to be given for this
C8Y.baseURL=https://dev.iot.solenis.com
C8Y.bootstrap.user=
C8Y.bootstrap.password=
C8Y.microservice.isolation=MULTI_TENANT

Error when the project is run with mvn spring-boot:run

[INFO] — spring-boot-maven-plugin:2.7.0:run (default-cli) @ cumulocity-microservice-templates —
[INFO] Attaching agents:
Exception in thread “main” java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationListener : org.springframework.boot.context.logging.LoggingApplicationListener
at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:449)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:431)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:424)
at org.springframework.boot.SpringApplication.(SpringApplication.java:268)
at org.springframework.boot.SpringApplication.(SpringApplication.java:246)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
at com.c8y.ms.templates.basic.App.main(App.java:11)
Caused by: java.lang.NoClassDefFoundError: org/springframework/context/event/GenericApplicationListener
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:467)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:284)
at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:442)
… 7 more
Caused by: java.lang.ClassNotFoundException: org.springframework.context.event.GenericApplicationListener
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
… 20 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.458 s
[INFO] Finished at: 2022-06-28T17:56:48+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.7.0:run (default-cli) on project cumulocity-microservice-templates: Application finished with exit code: 1 → [Help 1]
[ERROR]

Hey Sethu,
you need to set all missing properties in the properties file (C8Y.bootstrap.tenant, C8Y.bootstrap.user, C8Y.bootstrap.password) Tenant is an id of your tenant, you can find it in the Admin App by clicking on you email in the right upper corner. To get you bootstrap credentials, please refer to the documentation → Microservice SDK for Java - Cumulocity IoT Guides
You would need to either deploy your microservice or create an application entry before.
Best,
Nick

1 Like

It is important to follow the steps: https://github.com/SoftwareAG/cumulocity-microservice-templates/tree/main/basic#how-to-run-locally

Aquire the bootstrap information and add the values to properties:
C8Y.bootstrap.tenant
C8Y.bootstrap.user
C8Y.bootstrap.password

Mapping from request to property:

{
“password”: “************************”, → C8Y.bootstrap.password
“name”: “servicebootstrap_templates-basic”, → C8Y.bootstrap.user
“tenant”: “” ->> C8Y.bootstrap.tenant
}

Hi Nick,
I understand. I will set all the required things right today and let you know if am able to run.

thanks

Yes Alex, I will sure try these today and inform you of the outcome may be tomorrow.

Thanks,

Hi Alex,
I made only the minor change in the MeasurementController - commented out //@RequestMapping(path = “/measurements”)

I followed the ReadMe in the GIT and I am able to build and run the basic application now. But I am trying to call the end points from post man as below. Kindly help me on how to call the end points locally.

I tried with http://localhost:8080/latest/deviceId - it said unauthorized

Then I tried with https://localhost:8080/latest/deviceId

  • selected the Basic Auth
  • passed the bootstrap user name and credentials

But the Devices list is getting listed as it is done by the scheduling in the DeviceService. But I am trying to access the measurements from postman.

Result:

  1. configured application key differs from registered application key as below
  2. java.lang.IllegalArgumentException: Invalid character found in method name

Please refer the error from console:

2022-06-29 09:40:50.257 INFO 25048 — [ main] o.s.boot.web.servlet.RegistrationBean : Filter preAuthenticateServletFilter was not registered (disabled)
2022-06-29 09:40:50.258 INFO 25048 — [ main] o.s.boot.web.servlet.RegistrationBean : Filter postAuthenticateServletFilter was not registered (disabled)
2022-06-29 09:40:50.460 INFO 25048 — [ main] o.s.s.web.DefaultSecurityFilterChain : Will secure any request with [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@1c25b8a7, org.springframework.security.web.header.HeaderWriterFilter@41200e0c, org.springframework.security.web.authentication.logout.LogoutFilter@7646731d, com.cumulocity.microservice.security.token.CumulocityOAuthMicroserviceFilter@669513d8, com.cumulocity.microservice.security.filter.PreAuthenticateServletFilter@b7838a9, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@7249dadf, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@2ad3a1bb, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@200606de, com.cumulocity.microservice.security.filter.PostAuthenticateServletFilter@7fc6de5b, org.springframework.security.web.access.ExceptionTranslationFilter@72efb5c1, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@2db2cd5]
2022-06-29 09:40:50.552 INFO 25048 — [ main] c.c.m.s.TenantOptionPropertySource : Overriding application settings with tenant options is enabled.
2022-06-29 09:40:50.565 WARN 25048 — [ main] .m.s.s.i.MicroserviceSettingsServiceImpl : Loading tenant options using bootstrap credentials!
2022-06-29 09:40:52.687 INFO 25048 — [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 4 endpoint(s) beneath base path ‘’
2022-06-29 09:40:52.744 INFO 25048 — [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ‘’
2022-06-29 09:40:52.758 INFO 25048 — [ main] .s.s.i.MicroserviceSubscriptionScheduler : Start; subscriptionDelay = 10000, subscriptionInitialDelay = 30000
2022-06-29 09:40:52.764 INFO 25048 — [ main] com.c8y.ms.templates.basic.App : Started App in 5.28 seconds (JVM running for 5.809)

2022-06-29 09:41:23.827 WARN 25048 — [subscriptions-0] .s.r.MicroserviceSubscriptionsRepository : Configured application key ‘’ differs from the registered application key: ‘sethu-test-service’. Updating configuration.

2022-06-29 09:41:02.429 INFO 25048 — [nio-8080-exec-1] o.apache.coyote.http11.Http11Processor : Error parsing HTTP request header
Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.

java.lang.IllegalArgumentException: Invalid character found in method name [0x160x030x010x000xf70x010x000x000xf30x030x03P0x9d0xd50xb3l0xf20xce0xe90xcc0x950xc00xd20xb3gT0x110xd00x960xf50x100x970x0d0x970x070x9cp0x910x1160x090xc00x0e ]. HTTP method names must be tokens
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:419) ~[tomcat-embed-core-9.0.63.jar!/:na]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:271) ~[tomcat-embed-core-9.0.63.jar!/:na]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.63.jar!/:na]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890) ~[tomcat-embed-core-9.0.63.jar!/:na]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743) ~[tomcat-embed-core-9.0.63.jar!/:na]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.63.jar!/:na]
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-9.0.63.jar!/:na]
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-9.0.63.jar!/:na]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.63.jar!/:na]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.