springdoc-openapi-ui does not read provided yaml configuration - spring-boot

I'm trying to migrate app from autogenerating openapi from existing controllers and model to yaml specification(from which controller interfaces/models will be generated). YAML file is ready, bean OpenAPI providing some information is gone, I set springdoc.packages-to-scan= and tried to point to yaml file using:
springdoc.api-docs.path=/api.yaml and/or springdoc.swagger-ui.url=http://localhost:8080/ofs/api.yaml, but for some reason, while I get updated URL for 'source' yaml file, it is not the source file, it was somehow autogenerated. I see wrong servers, some default title etc.
sole maven dependency is:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
</dependency>
I didn't find any autoconfiguration. I think I see results of some "we will do magic for you" default configuration, but I cannot find anywhere (tutorials/documentation) how to force system to: "don't do anything, use this configuration".
Can someone advice / point me to documentation(specific section) or some tutorial? Or did I get it wrong and in this case I should not use springdoc-openapi-ui at all?

Related

How to specify Log4j2 configuration file in spring boot application

I am using log4j2 in my spring boot application. This works in all respects re: excluding slf4j, including log4j2, etc.
But when the application deploys I need to customize the file for each target host. I have created an ansible role that does this. Ultimately I end up with a log4j2.xml file deployed in another directory e.g. /prod/produsrX/data/log4j2.xml.
I am using the spring-boot-maven-plugin "repackage" goal to generate an executable jar file. It doesn't seem like that should matter but it is a data point in the problem.
This was supposed to be the easiest part of the project. Always before I have just been able to set -Dlog4j.configurationFile - advice which is echoed on about 3,000 web pages and DOES NOT WORK in Spring Boot 2.1.3.
The most useful info I've found is this question. It talks about using -Dlogging.config because logging must be initialized before other properties are read. Unfortunately that didn't help either.
I did find one example that suggested specifying the above directory in a -classpath parameter to java. But that didn't help either.
Does anyone know how to get a spring boot application to read the log4j2.xml file?
The property actually has to be put into the application context (e.g. application.yml). Using a -D property does not work!
logging:
config: /prod/produsrX/data/log4j2.xml #fully qualified name to your log4j.xml

Hacker rank Clases addition for Rest api task

I have been provided with a task of creating a Rest Api for a provided situation and I tried creating it in my IDE but when I am trying to copy it in Hackerrank editor it's giving a compilation error for the Annotations that I have added for creating the rest api like #SpringBootApplication and #RestController.
I did it on IDE locally and copied all my classes to the single editor that is provided for running your code but its giving compilation errors on various Annotations used.
Can someone let me know what is the way of creating different classes in the editor if you have multiple classes in your solution with some extra annotations.
You need add this dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
then it will work.
Refer to this hacker rank link to get and idea about where should libraries be input.

Spring Boot Freemarker - html escaping by default

Is there any convenient way to enable html escaping by default for all freemarker templates when using spring boot autoconfiguration?
If not, what's proper way to add any of following solutions (keeping spring boot autoconfiguration defaults except of template loader)?
Default escaping in Freemarker
http://watchitlater.com/blog/2011/10/default-html-escape-using-freemarker/
After following ddekany's advice to use 2.3.24 here's solution:
Modify all template names to .ftlh (required by freemarker to automatically turn on HTML escaper) - including spring.ftl if it's being used. Updated spring.ftlh migh need some '?no_esc' additions for attributes
Adjust freemarker config to use those files:
spring.freemarker.suffix=.ftlh
spring.freemarker.settings.recognize_standard_file_extensions=true
Modify pom.xml to use freemarker 2.3.24:
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>freemarker-2.3.24-pre01</version>
</dependency>
Following solution is to use local JAR file because 2.3.24 is not yet on maven:
mvn install:install-file -Dfile="freemarker-2.3.24-pre01.jar" -DgroupId="org.freemarker" -DartifactId="freemarker" -Dversion="freemarker-2.3.24-pre01" -Dpackaging=jar
Voila, automatic freemarker HTML escaping for Spring Boot ;)
FreeMarker 2.3.24 has auto-escaping as core feature, though when I write this it's not yet released. Until that (1-2 mongth I guess), 2.3.24-pre01 is downloadable from the homepage, or you can build the 2.3-gae branch head (though not much has changed if you are only using auto-escaping among the 2.3.24 features). Auto-escaping is currently described there: http://freemarker.incubator.apache.org/builds/2.3.24-pre01/_html/dgui_misc_autoescaping.html
If you can't use 2.3.24 in this form, as the first post you have linked describes, you can use a custom TemplateLoader. As templateLoader (template_loader) is just a FreeMarker configuration setting, hopefully it can be set in Spring too.

Spring Roo NoClassDefFoundError

my primary attempt is to build a CRUD app using Roo, following the example here:
https://www.icts.uiowa.edu/confluence/display/ICTSit/Spring+Roo+Tutorial
I am using Roo 1.2.5, Maven 3.1.1, and Spring 3.2.6 on JRE7.
This has been the best tutorial I have found so far. If anyone has a better example, please share!
However, when I execute the project in my Tomcat environment things still break. The primary error from there is:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NoClassDefFoundError: org/springframework/util/MimeType
I have built multiple projects using Roo over the past few days, either from this tutorial or 10 others that all start with the reverse engineer command, and all give me the same type of a NoClassDefFoundError, either with this class or another. I understand this means that my pom.xml is more than likely incorrect, but I am hoping this is an issue with my configuration rather than something all Roo developers have simply accepted as manual maintenance.
Any advice would be tremendous... is it possible that the version of Roo combined with Spring and Maven I am using is simply buggy? I would love to use this framework/toolkit, but am nearing the point where manually writing the scaffolding by hand may be more straightforward.
.... UPDATE:
By adding the following dependency manually, I was able to run the project. However, I want to leave the question open to see if anyone further knows whether this missing jar is a known bug given the version of Spring Roo I am using, or otherwise:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>
Thanks!
The best examples are those included in Roo: clinic.roo, pizzashop.roo, etc
Just run Roo and execute any of them as follows:
/_/ |_|\____/\____/ 1.2.4.RELEASE [rev 75337cf]
Welcome to Spring Roo. For assistance press TAB or type "hint" then hit ENTER.
roo> script --file clinic.roo
On the other side, the reference doc is a good starting point: http://docs.spring.io/spring-roo/reference/html/
Finally, about java.lang.NoClassDefFoundError: org/springframework/util/MimeType note MimeType class was included in Spring 4 and Roo sets up your project for Spring 3, so you must customize the pom.xml as needed.

glassfish 4 and jersey-media-multipart 2 don't work with beans.xml

I am using glassfish 4 to build some restful apps using the standard Java 7EE stack recently released.
My basic restful service works fine, but now I want to handle incoming file uploads which use the multipart mime type within the same service.
I found a POC jersey maven example (multipart-webapp) referred to in the https://jersey.java.net/documentation/latest/user-guide.html
and this deploys and works fine.
However, as soon as I build on this framework to include dependency injection, and in particular, as soon as I create a beans.xml file ( even an empty one ), I get all sorts of errors like:
SEVERE: Exception while loading the app : CDI deployment failure:WELD-001408 Unsatisfied dependencies for type [Providers] with qualifiers [#Default] at injection point [[BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] #Inject public org.glassfish.jersey.media.multipart.internal.MultiPartReaderServerSide(#Context Providers, Provider)]
I've tried using the new bean-discovery-mode attribute set to all or none in my beans.xml file but it makes no difference.
Is this a bug in Glassfish or Jersey, or are they currently incompatible even though Glassfish includes all the jars involved, or am I doing something really silly?
It turns out that the error messages and beans.xml behaviour are red herrings. To help anyone with the same problem, this is what you need to do to use multipart mime inside a restful interface on glassfish.
Make sure the library is added only at compile time. If you use netbeans, this means adding multipart-mime-xxx.jar from the glassfish/modules directory as a library, but unclicking the 'package' button, so it is not included in the war package ( since it's already inside glassfish anyway.
If you are using maven, you achieve the same result by using a provided tag inside the dependency:
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<scope>provided</scope>
</dependency>
If you are using a restful template generated by netbeans as your starting point, you will have a file called application-config.java which has been generated for you. Add the line:
resources.add(MultiPartFeature.class);
immediately above the line
addRestResourceClasses(resources);
Now you should find that you can safely use the various annotations for multipart mime in jersey.

Resources