I have a problem when builing native quarkus image and try to use mongo panache query.
If i using dev profile or builing normal jar everything working.
Here is my Dockerfile.native
## Stage 1 : build with maven builder image with native capabilities
FROM quay.io/quarkus/centos-quarkus-maven:19.2.1 AS build
COPY backend /usr/src/app/backend
COPY frontend /usr/src/app/frontend
COPY pom.xml /usr/src/app/
USER root
RUN chown -R quarkus /usr/src/app
USER quarkus
RUN cd /usr/src/app/ && mvn clean package -Pnative -Dnative-image.xmx=4g
RUN mkdir -p /tmp/ssl-libs/lib \
&& cp /opt/graalvm/jre/lib/security/cacerts /tmp/ssl-libs \
&& cp /opt/graalvm/jre/lib/amd64/libsunec.so /tmp/ssl-libs/lib/
## Stage 2 : create the docker final image
FROM registry.access.redhat.com/ubi8/ubi-minimal
WORKDIR /work/
COPY --from=build /usr/src/app/backend/target/*-runner /work/application
COPY --from=build /tmp/ssl-libs/ /work/
RUN chmod 775 /work
EXPOSE 8080
CMD ["./application", "-Dquarkus.http.host=0.0.0.0", "-Djava.library.path=/work/lib", "-Djavax.net.ssl.trustStore=/work/cacerts"]
ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (vert.x-worker-thread-1) HTTP Request to /api/budget failed, error id: 86ff4366-b0d2-49c5-87f7-e6eee9d71feb-1: org.jboss.resteasy.spi.UnhandledException: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class domain.Budget.
at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:106)
Did anyone have a similar problem?
EDIT
domain (Period and Category has also default construstors)
#MongoEntity(collection = "Budget")
public class Budget {
private ObjectId id;
private Period period;
private List<Category> categories;
public Budget() {
period = new Period();
categories = new ArrayList<>();
}
//business method getter setters...
}
repository
#ApplicationScoped
public class BudgetRepository implements PanacheMongoRepository<Budget> {
}
controller
#GET
#Path("/budget")
#Produces("application/json")
public Response budget() {
Budget budget = repository.listAll().get(0);
return Response.ok(budget).build();
}
GraalVM native-image needs to know wich classes needs to be accessible by relfection. As your REST endpoint use a Response return type, Quarkus cannot enlist for reflection your Budget class automaticaly so you need to use the #RegisterFroReflection annotation for this.
There is a PR that will do it for you, so you will soon no more need to do it by yourself: https://github.com/quarkusio/quarkus/pull/6326/files
But as long as this is not merged, you need to add the #RegisterFroReflection annotation on your Budget class.
Related
Running the following command mvn -U clean install is there a way to check -U from within my custom Mojo?
I checked available items in AbstractMojo.getPluginContext() but didn't find anything for command line.
Technically it is possible get the information via the MavenSession:
#Parameter(defaultValue = "${session}", readonly = true)
private MavenSession session;
public void execute() {
...
if (session.getRequest().isNoSnapshotUpdates()) {
...
}
}
But I would ask why do you need such information within a plugin?
I am working on a Spring MVC and Hibernate Project.When i build war clean install and deploy in tomact.In console old code is running Means like this is my index controller
#Controller
#RequestMapping({ "/index" })
public class IndexController {
private final Logger logger =
LogManager.getLogger(this.getClass().getSimpleName());
#RequestMapping(method = RequestMethod.GET)
public String index(ModelMap model, final Principal principal) {
//logger.debug("Enter in Get method IndexController");
return "index";
}
}
you can see i comment the logger but it print in console.So i think it comes from another controller then i delete all controllers from my code and after deploying it still print logger and i also remove logger from this controller and after deploying it still print logger.I dont know why my code is not update in war.Can anyone help me
Please clear local repository and then do clean install
For windows you can find .m2 repository in your C:\Users\{yourUsername}\.m2
I've a slight race condition when it comes to loading spring properties for an integration test using #TestPropertySource.
Consider the following;
test (using Spock but same for JUnit)
#SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
#TestPropertySource(locations = "classpath:test/simple-test.properties")
class SimpleStuff extends Specification {
public static final String inputDirectoryLocation = "/tmp/input-test-folder"
def "test method"() {
//do test stuff
}
}
simple-test.properties
inputDirectoryLocation=/tmp/input-test-folder
Spring Component
#Component
class SpringComponent {
#Value('${inputDirectoryLocation}')
String inputDirectory;
//do other stuff
}
The above works fine but how would I make the test fully isolated and NOT have a dependency on the FileSystem having the folder /tmp/input-test-folder (as not all users running this test are allowed to create a /tmp folder on their FS)
For example, I would like to use something like
inputDirectoryLocation = Files.createTempDirectory()
so that
#Value('${inputDirectoryLocation}')
String inputDirectory;//equals the output of Files.createTempDirectory()
resulting in test using the OS default temporary folder location & allows us to have the test simply delete the temp folder on cleanup. Is there an eloquent solution to solve the above?
Note: using Spring boot 1.5
Turned out simple enough - simply had to change the value in the properties file to refer to the
inputDirectoryLocation=${java.io.tmpdir}/input-test-folder
Then have my Spock specification create the temp folder prior to launching Spring (by using the setup() fixture method )
Hi all,
at Can DropWizard serve assets from outside the jar file? I have read, that it is possible to serve static files outside of jar file with dropwizard-configurable-assets-bundle (later only DCAB).
But there are no examples available on the web. The only one, at their github page is not very helpful for me.
Firstly, there is said, that I should implement AssetsBundleConfiguration, but there is no mention where should I use it then.
Next, in service I should put this row:
bootstrap.addBundle(new ConfiguredAssetsBundle("/assets/", "/dashboard/"));
But unfortunately, it is showing me an error, that it is not applicable for that argument.
And in third part there is some yaml, but I don't know, whether it's produced by bundle, or whether I should put it somewhere.
And I noticed, that paths are relative to src/main/resources. Is there also option how to access files outside of that?
So the steps are pretty much like described in the README.md
You start with dependency
dependencies {
compile 'com.bazaarvoice.dropwizard:dropwizard-configurable-assets-bundle:0.2.0-rc1'
}
AssetBundleConfiguration interface needs to be implemented by you standard configuration file. So in my case:
public class BookRespositoryConfiguration extends Configuration
implements AssetsBundleConfiguration {
#Valid
#NotNull
#JsonProperty
private final AssetsConfiguration assets = new AssetsConfiguration();
#Override
public AssetsConfiguration getAssetsConfiguration() {
return assets;
}
}
This configuration is referred in you Application class
public class BooksRepositoryApplication
extends Application<BookRespositoryConfiguration> {
#Override
public void initialize(Bootstrap bootstrap) {
bootstrap.addBundle(new ConfiguredAssetsBundle("/assets/", "/books/"));
}
#Override
public void run(BookRespositoryConfiguration configuration,
Environment environment) throws Exception {
//...
}
}
And finally configuration. The configuration path is relative to the document-root, so in my case the assets are located outside the application folder.
assets:
overrides:
/books: ../book-repository
Now after running the app you can easily navigate to http://localhost:8080/books/some-static-files.html
Look at upto-date dropwizard-configurable-assets-bundle maintained at official dropwizard-bundles.
https://github.com/dropwizard-bundles/dropwizard-configurable-assets-bundle.
I'm just trying to add the Lombok plugin to IntelliJ IDEA 12.1.4. on a Mac machine, see:
The documentation on this page (https://code.google.com/p/lombok-intellij-plugin/) said:
...just download, unzip to IntelliJ plugin directory and try out!
First I had to use EasyFind to find out this folder, because it was invisible...
than I put the plugin at the directory:
~/Library/Application Support/IntelliJIdeaXX
as specified on this page (http://devnet.jetbrains.com/docs/DOC-181), and redeployed the app. But the code keeps showing compile errors on every line that uses Lombok's features, even the simple #Getter and #Setter annotations.
so I've restarted the IDE, the highlighted compile time errors were gone, but when I run it on Glassfish it caught the compile time error, on the same line of code: trying to get a property using getter method that is generated by Lombok.
Exception:
Caused by: java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>
at com.codepianist.model.Model.<clinit>(Model.java:40)
... 50 more
Error:
// Error code
#Getter
private static Map<String, Language> LANGUAGES_MAP = new HashMap();
static {
for(Language l : LANGUAGES)
LANGUAGES_MAP.put(l.getId(), l); // line 40
}
Language Class:
// Language class
public class Language implements Serializable{
public Language(){}
public Language(String id, String flag) {
this.id = id;
this.flag = flag;
this.locale = new Locale(id);
}
#Getter private String id;
#Getter private String flag;
#Getter private Locale locale;
}
For information: Tried to call mvn clean install -e from my Terminal and not a single error. And the same app, runs fine with Netbeans.
May I have to configure the plugin on any IDE section?
I'm migrating from Netbeans, and just installed IntelliJ IDE, so I'm pretty new to it.
Thanks in advance.
Try installing the plugin using the following guide: http://www.jetbrains.com/idea/features/open_api_plugin_manager.html