springdoc-openapi doesnt pick up changes in controller classes - spring-boot

I have a 3-module Springboot multi-module maven project with a structure like so:
parent
|- module 1
|- module 2
|- module 3
The maven dependency for spring-openapi is in the parent pom, while the main class is in module 1.
The problem is that when I examine the Swagger api, I only see the documentation for the rest endpoints from module 1, and not those in 2 or 3.
I experimented by putting the openapi dependency in module 3 and re-building but that doesn't make a difference. Is it not possible to get all the rest-endpoints across all modules published all at once?
Some more info: here are some properties from my application.properties:
springdoc.packagesToScan=com.sxxxxxxxxx
springdoc.pathsToMatch=/a/**, /d/**
These are my dependencies:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.9</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-security</artifactId>
<version>1.6.9</version>
</dependency>
I thought that this Q&A might help (but it didnt): OpenAPI & spring-doc not finding all mappings in a controller class
I've been doing some experimentation:
I added a Test Controller, and it appeared in the docs. Then I deleted the Test Controller from the code base, but it still appears in the docs
I've changed the http response codes to some of the endpoints in the documentation, but those aren't picked up.
It almost seems like once it does the initial generation of documentation for a rest controller, it forgets about looking at it again for any further changes.
Does any one have an idea?
Thanks

Related

Maven property overriding conflict between parent/bom

I am currently facing an issue with my maven configuration. I was thinking it will work in a way where versions in MyBom will have higher priority on the grand-grand-parent defined versions.
This is the setup :
enter image description here
In spring-dependencies, I have this version <atomikos.version>4.0.6</atomikos.version>.
In myBom, I have this version <atomikos.version>5.0.106</atomikos.version>.
Both spring-dependencies and MyBom have the
<dependency>
<groupId>com.atomikos</groupId>
<artifactId>transactions-jta</artifactId>
<version>${atomikos.version}</version>
</dependency>
I have imported the bom as usual in "MyParent":
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.test</groupId>
<artifactId>myBom</artifactId>
<version>${myBom.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Finally, in "MyProject", when I am showing the effective pom, it uses the version 4.0.6 coming from the spring-dependencies.
I was expecting the version to be 5.0.106 as the bom redefine it in a sublayer.
Note that it can work with any dependency which is common between bom and parent.
So, currently, my only viable solution is to manually set the the version in "MyParent" which is making the creation of "MyBom" useless...
Can you confirm what is correct ? My assumption (meaning I have a misconfiguration somewhere) or the current behavior, meaning "MyBom" is worthless.
As far as I know, "direct" entries in the dependencyManagement always take precedent over BOMs, not matter what the inheritance level is.
You should probably just override the <atomikos.version> property.
This is not possible to override parents version from "MyBom" project. The only solution is to remove the spring-boot-starter-parent as parent and import the spring-dependencies at same level of "MyBom" import.
I found the solution but I would like to thank #J Fabian Meyer to also point the correct solution.
The dependencyManagement is just a declaration of what the version of the dependency should be when really used as a project dependency. Thus you still should declare (use) the myBom dependency. Also, the scope "import" is invalid.
See the documentation
https://maven.apache.org/pom.html#dependency-management
https://maven.apache.org/pom.html#Dependencies

How to configure Swagger with Openapi

I just started using springdoc-openapi. I want to be able to customize the Swagger for things like background color, logo, etc. Is there a way to do that? I see that springdoc-openapi-ui includes webjars/swagger-ui, but I'd hate to just run a customize version. Would prefer to do it as an update so it doesn't interfere with future upgrades
Just to experiment, I've tried copying the entire swagger-ui distribution to my resources directory: resources/swagger-ui. I've also tried resources/webjars/swagger-ui.
In my pom, I have
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.6</version>
<exclusions>
<exclusion>
<groupId>org.webjars</groupId>
<artifactId>swagger-ui</artifactId>
</exclusion>
</exclusions>
</dependency>
So it should only use my local version. But I get a 404
GET "/swagger-ui/index.html", parameters={}
Mapped to ResourceHttpRequestHandler [classpath [META-INF/resources/webjars/]]
Resource not found
Completed 404 NOT_FOUND
Not sure why it's not finding it at swagger-ui/index.html
It looks like you need to set some of the variables in the .properties file:
try
springdoc.swagger-ui.path=/swagger <- sets the url path so you can see localhost:8080/swagger/index.html
springdoc.swagger-ui.enabled=true <- sets the swagger-ui to enabled
springdoc.api-docs.enabled=true <- sets the springdoc openapi enpoint to enabled
I would look here for other property setting you might need - such as turning off swagger in production, etc...
https://springdoc.org/#properties
As for customization, you will have to create your own .html page and disable the use of the default one.
springdoc.swagger-ui.path=MyNewHtmlFile.html
I think is the property name for setting your own .html file.

WebClient create java.lang.ExceptionInInitializerError: null ExchangeStrategies.withDefaults

I'm trying to play around Spring WebFlux Webclient.
Tried to create a simple webclient in a quartz cron job
this.webClient = WebClient.create(this.queryUrl);
I made sure the queryUrl is valid.
However, I've got an error as following:
java.lang.ExceptionInInitializerError: null
at org.springframework.web.reactive.function.client.ExchangeStrategies.withDefaults(ExchangeStrategies.java:67)
at org.springframework.web.reactive.function.client.DefaultWebClientBuilder.initExchangeStrategies(DefaultWebClientBuilder.java:302)
at org.springframework.web.reactive.function.client.DefaultWebClientBuilder.build(DefaultWebClientBuilder.java:269)
at org.springframework.web.reactive.function.client.WebClient.create(WebClient.java:154)
Tracing into the code, I've found that
DefaultExchangeStrategiesBuilder is null.
Does anyone have any idea what is missing?
It's a simple web client.
Thanks.
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.0</version>
</dependency>
Adding these dependencies and making sure the versions are the same.
I only had jackson-core before.
I tried to move the job out of quartz and ran it directly in main.
it still threw an exception, but it's different and I then looked it up
and some one has asked the issue and the solution to make sure both jackson packages need to be included and versions must be same.
I then added them to the pom file. try to run the job and it worked.
Putting the job back to quartz to run and it also worked.

WildFly 10, JCache - method caching

i have simple application using Spring Boot. I wanted allow method caching with JSR107 - JCache. So with help of tutorial i put together this code :
#CacheResult(cacheName = "testpoc")
public Country getCountry(Integer id){
System.out.println("---> Loading country with code '" + id + "'");
return new Country(id, "X", "Title");
}
with this POM file
...
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
...
(dependency 'spring-boot-starter-web' is there for simple REST service which call getCountry method)
Everything works like documentations says - method is invoked only once.
Now i wanted to try it on WildFly 10 application server
I have modified pom file :
excluded tomcat
exluded spring-boot-starter-cache
added infinispan-jcache (because i want to use cache configured / managed by wildfly in standalone/domain.xml)
Check pom file here on pastebin.
Problem is, that i am receiving following error :
Cannot find cache named 'java:jboss/infinispan/app-cache'
(i have tried to use both JNDI assigned and name to infinispan cache configured in wildfly).
Following code created Cache object (so i can used it) :
CacheManager cacheManager = Caching.getCachingProvider().getCacheManager();
Cache<String, String> cache = cacheManager.createCache("testpoc", new MutableConfiguration<String, String>());
Question :
It is possible to use JCache method caching on WildFly 10 using Infinispan managed by WildFly ?
Or Infinispan should be used for method caching like JCache, hence JCache has "more functionality" than Infinispan.
Thank you very much
PS :It is not problem for me to put whole code on github and post link - it is few lines of code ...
There are a couple of problems with your approach so let me go through them in steps.
At first you need to use proper Infinispan setup. Infinispan bits shipped with WF should be considered as internal or private. In order to use Infinispan in your app properly - either add org.infinispan:infinispan-embedded to your deployment or install Infinispan Wildfly modules. You can find installation guide here (it's a bit outdated but still, the procedure is exactly the same - unpack modules into WF and use Dependencies MANIFEST.MF entry).
Once you have successfully installed Infinispan (or added it to your app), you need to consider whether you want to use Spring Cache or JCache. If you're only interested in using annotations - I would recommend the former since it's much easier to setup (all you need to do is to add #EnableCaching to one of your configurations). Finally with Spring Cache you will create an Infinispan CacheManager bean. An example can be found here.
Final note - if you still need to use JCache - use this manual to setup Caching Provider.

spring boot 1.3.1 devtools hot reload not work if your project name is spring-boot

Spring boot 1.3.1.RELEASE, used devtools.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
Now I add some code in controller method, e.g.
logger.info("delete {} ", name);
but in eclipse console, nothing output, and access this url , the new add logger did not output. So why is so? why hot reload not work?
I found something could explain this phenomenon. Because my project name is spring-boot, and run Application class in eclispe you could see:
you could see after Application name appended (1)
I don't know what's this mean.
After rename project name to anything else(e.g. spring-boot-reservation), now I found devtools could work normally.
And this time the number after Application name is changed to 2,

Resources