CPS-2480 Multiple base package

CPS-2480 Multiple base package

CPS-2480: Multiple base packageClosed

 

Description:

As a plugin developer I want to use multiple base package in NCMP-CPS jar.

Affected version:

CPS 3.5.4

Expected behavior:

I want to configure the base packages with the spring.component.scan variable from the application.yaml .

Impact:

It affects the Spring base application.

Possible solution:

Use ComponentScan annotation

  • always put your ComponentScan annotation after SpringBootApplication, because the SpringBootApplication will load the configuration.

  • the ComponentScan annotation will override the original package, so when you want some classes from the original you should add them too.

  • you can use multiple package with ";": @ComponentScan(basePackages = "my.package.one;my.package.two")

  • you can use configuration variables and default: @ComponentScan(basePackages = "${spring.component.scan:<my.default.package>}")

Example:

package com.myapp.deff.pckg; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @ComponentScan(basePackages = "${spring.component.scan:com.myapp.deff.pckg}") public class Application { public static void main(final String[] args) { SpringApplication.run(Application.class, args); } }

 

 

Investigation:

Adding ComponentScan to application.java:

@EnableRetry @SpringBootApplication @ComponentScan(basePackages = "org.onap.cps") public class Application { public static void main(final String[] args) { SpringApplication.run(Application.class, args); } }

Failure from mvn clean install:

Caused by: org.springframework.expression.spel.SpelParseException: Expression [${cps.tracing.enabled} && 'grpc'.equals('${cps.tracing.exporter.protocol}')] @1: EL1041E: After parsing a valid expression, there is still more data in the expression: 'lcurly({)'

 

Further Investigation:

String “org.onap.cps “ not spel compliant.

Change to spel compliant variable:

@EnableRetry @SpringBootApplication @ComponentScan(basePackages = "#{scan.base.package}") public class Application { public static void main(final String[] args) { SpringApplication.run(Application.class, args); } }

Failure from mvn clean install:

[ERROR] Failures: [ERROR] ControllerSecuritySpec.Get request with authentication:46 Condition not satisfied: response.status == HttpStatus.OK.value() | | | | | | | 404 | | | 200 | | | 200 OK | | class org.springframework.http.HttpStatus | false <org.springframework.mock.web.MockHttpServletResponse@59c126af outputStreamAccessAllowed=true writerAccessAllowed=true defaultCharacterEncoding=ISO-8859-1 characterEncoding=ISO-8859-1 characterEncodingSet=false content= outputStream=org.springframework.mock.web.MockHttpServletResponse$ResponseServletOutputStream@7d3a52aa writer=null contentLength=0 contentType=null bufferSize=4096 committed=true locale=en_US cookies=[] headers=[Vary:[Origin, Access-Control-Request-Method, Access-Control-Request-Headers]] status=404 errorMessage=No static resource test. forwardedUrl=null includedUrls=[]> [INFO] [ERROR] Tests run: 13, Failures: 1, Errors: 0, Skipped: 2

Error starting docker container

{"logTimeStamp":"2024-11-26T15:54:48.241Z","logLevel":"ERROR","principalId":"cpsuser","serviceName":"cps-application","message":"\n\n***************************\nAPPLICATION FAILED TO START\n***************************\n\nDescription:\n\nParameter 0 of constructor in org.onap.cps.ri.repository.FragmentRepositoryCpsPathQueryImpl required a bean of type 'org.onap.cps.ri.repository.FragmentQueryBuilder' that could not be found.\n\n\nAction:\n\nConsider defining a bean of type 'org.onap.cps.ri.repository.FragmentQueryBuilder' in your configuration.\n","processId":"1","threadName":"main","class":"o.s.b.d.LoggingFailureAnalysisReporter"}