I Can see the following warning with #ConfigurationProperties Annotation
When using #ConfigurationProperties it is recommended to add 'spring-boot-configuration-processor' to your classpath to generate configuration metadata
Everything working fine. What it meant for?
If you add an optional dependency to the “spring-boot-configuration-processor”, your module will hold a meta-data file that is generated at compile time with details about your properties. IDEs can then pick that up to show you content assist/auto-completion. STS, Intellij IDEA and Netbeans have such support .
It is an annotation processor that generates metadata about classes in your application that are annotated with #ConfigurationProperties.
More info here: http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#configuration-metadata
https://docs.spring.io/spring-boot/docs/2.1.1.RELEASE/reference/htmlsingle/#configuration-metadata-annotation-processor
Related
When I try to build my Enterprise Project in Netbeans with ant, i got this exception:
warning: Supported source version 'RELEASE_6' from annotation
processor
'org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor'
less than -source '1.8'
Note: Creating static metadata factory ...
An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file
javax/persistence/PersistenceException
I only have some entityclasses in my ejb module.
This error is reported as a bug in NetBeans (with a resolved status as it turns out to be considered as a "user error"). Below is the main comment that explains the problem and gives the solution:
"ClassFormatError: Absent Code attribute in method..." is always indication that javaee-api-6.0.jar is used for runtime execution. The jar contains only method signatures (method bodies are stripped) and is suitable only for compilation. In future versions of javac there might be better error message.
The problem here is that javaee-api-6.0.jar is on classpath before EclipseLink jars and when EclipseLink annotation processor is started classes from javaee-api-6.0.jar are used instead of classes from EclipseLink. First thing is that javaee-api-6.0.jar should be removed from classpath of EJB project - it should not be needed as EJB project has an Application server selected and the project takes EE 6 APIs from that server.
As I understand the comment, you should try removing any reference to javaee-api-6.0.jar (which contains only "dummy" classes) from the classpath of the project, because the EclipseLink library should provide the correct classes used by the annotation processor.
Also, this question seems to tackle the same issue.
when you use the insert code and automatic bean creation it adds the Java EE 6
API library . I deleted the library and add the Java EE 7 API.
I'm having trouble with a Spring Boot app that is not loading a config class with 2 beans in it. The weird thing is that another config class in the same package gets loaded.
Both config classes have #Configuration in them. The one that doesn't load also has a #ComponentScan(basePackages = {"com.example.package.in.jar"}) in it.
The base packages value refers to a package in a loaded jar file.
I'm using Gradle 3.4.1, Spring Boot 1.5.3. When I turn on Spring debugging, it shows the other config class being found and loaded, but it just skips over the other one. No exceptions are thrown - no errors at all.
It would be one thing if the code didn't run, but at least load the class or throw an error, but the log file that was created showed no errors.
Use #EntityScan("com.yourpackage*") will check all the packages starts with "com.yourpackage"
Refer https://github.com/Roshanmutha/JPARepo_44149690/blob/master/src/main/java/com/rcmutha/usl/controller/Application.java
So it turns out that the problem was that it the file wasn't even being seen, period. After attempting the suggestions, I found another option to try: #ImportAutoConfiguration. I used this annotation in the main Spring Boot app file and specified the files in my config package. This is when the compiler said that it couldn't resolve the file I was having problems with.
I cut out the contents, deleted the file and re-created it with a slightly different name, pasted back the contents and update the file list for the annotation. It worked!
The file showed up in the file tree in IntelliJ, but it wasn't being seen by the compiler, so it wasn't being configured. Within the annotation it had to look for it explicitly, and then the error was produced.
Thank you to those that posted suggestions.
Les
I'm having a problem properly setting up spring boot for my multi-module maven project.
There is a module "api" that uses another module "core". Api has an application.properties file that contains spring.mail.host=xxx. According to the spring boot documentation this provides you with a default implementation of the JavaMailSender interface, ready to be autowired.
However the class that is responsible for sending out the e-mails resides in the "core" package. When I try to build that module the build fails because no implementation of JavaMailSender can be found.
My guess then was that the mailing config should reside in "core" in a separate application.properties. I created that and moved the spring.mail.host property from the "api" to the "core" property file.
This time the core module builds successfully, but "api" fails to build because of the same exception, so I think I just moved the problem.
I don't understand the required structure for handling this type of situations well enough so I was wondering what the correct way is for having a "core" module containing all the correct configuration for sending mails and having other modules use the mailing code and config that resides in it.
I found the answer in another stack overflow question: How to add multiple application.properties files in spring-boot?
It turns out there can only be 1 application.properties file in the final jar that spring boot creates. To have multiple files you have to rename one of the files to something custom. I named the properties of the core module "core-application.properties".
Then in the API module I added this to the spring boot application class:
#SpringBootApplication
#PropertySource(value = {"core-application.properties", "application.properties"})
Doing this I can correctly use the base properties file and overwrite them in the more specific modules. Also you can still create profile-specific properties file (core-application-production.properties) with this setup, no need to add those to the propertysource manually). Note that #PropertySource does not work for yaml configuration files at this moment.
there is one effective application.properties per project. you just keep 2 properties file for a success build.
when api module use core module, the application.properties in core module is overwrite by api.
Your API's pom.xml must has dependency of CORE module.
the solution is to define properties files as a value of #PropertiesSource in Starter class.
but it is beter to put "classpath:" behind the properties files.
for example in Intellij idea after adding the "classpatch:" word berhind the files name, values become to link. like this:
#SpringBootApplication
#PropertySource(value = {"classpath:core-application.properties", "classpath:application.properties"})
I hope to helped you.
I was playing with Java annotation processing. Application build fails in IntelliJ IDEA, while a maven build ends successfully. I am sure that provider class exists, yet I get the following error:
java: Bad service configuration file, or exception thrown while constructing Processor object: javax.annotation.processing.Processor: Provider <my class> not found.
I suppose that's because of a module X, that should be compiled with -proc:none argument. But I need annotation processing to be enabled for the rest of application. How to configure IntelliJ IDEA build proccess to skip a specific module during annotation proccessing?
You need to configure a separate annotation profile for your module.
Create an annotation profile
In the Annotation Processors page, click .
In the 'Create new profile' dialog box, specify the profile name.
Associate a module with an annotation profile
Select your module in the list of modules under a default profile. (By default, all the modules of a project are associated with the default profile.)
Click , or press F6.
From the drop-down list, select the target profile to move the selected module to.
Configure annotation processing for a profile
Enable annotation processing for the default profile.
Disable annotation processing for the profile, you've just created.
This answer is based on an article from IntelliJ IDEA Help.
I am using hibernate-release-4.2.4.Final version and tried using annotations instead of the hbm.xml file. But while running, it always throws an-annotation-configuration-instance-is-required-to-use-error.
When I tried importing org.hibernate.AnnotationConfiguration it showed the class was deprecated.
Then I tried copying Annotation configuration class file from the hibernate-annotation.jar and used and it in the hibernate3.jar and it worked fine.
My question is how to initialize a annotation configuration instance in the newer version of Hibernate release?
In Hibernate 4 you should not use AnnotationConfiguration anymore, use Configuration instead.
Use HibernateUtils or other session factory builder to build the session factory.
An example of such utility you could find here.