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.
Related
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?
I try to implement a microservice client to receive multipart form-data. I'm using Eclipse Microprofile and Openliberty. Therefore, I used the example sketched on https://openliberty.io/docs/21.0.0.6/send-receive-multipart-jaxrs.html.
In the example I see a method having a parameter with type IAttachment. However, I don't have a library providing this interface in my workspace (Eclipse).
How do I need to configure my pom.xml to get this interface?
Which library should provide this interface?
The IAttachment class is a WebSphere/Liberty-specific interface, so you'd need to add this dependency to your pom.xml:
<dependency>
<groupId>com.ibm.websphere.appserver.api</groupId>
<artifactId>com.ibm.websphere.appserver.api.jaxrs20</artifactId>
<version>1.1.54</version>
<scope>provided</scope>
</dependency>
In future versions of the Jakarta REST specification, you will be able to use a spec-defined interface, making your app more portable. See https://github.com/eclipse-ee4j/jaxrs-api/issues/418 for more details.
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.
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.
I have managed to get basic unit testing working, however when I add a unit test to project-java I get an error of class not found, looking into it it seems when compiling the testing classes, it dosn't copy the main classes from the project-core, does anyone have any idea how to fix this in maven?
Edit:
To make things more clear, I do know where to place the tests, I have placed in project-java/src/tests However What I mean is it doesnt invlude the clases from project-core/src
A better approach is to add your tests to core/src/test/java and then add a test dependency on playn-java to your core/pom.xml:
<dependency>
<groupId>com.googlecode.playn</groupId>
<artifactId>playn-java</artifactId>
<version>${playn.version}</version>
<scope>test</scope>
</dependency>
You need to store all yours tests not in src/main, but in src/test.
I used JUnit with this guide: Using Junit
I went a different route with this in the end, and actually made a playn-testframework.
a simple playn- project that acted like playn-java etc, but would not render to screen, and had extra callbacks for the tests to use, such as to simulate mouse/keyboard events.