-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PR #382: Added spring-boot autoconfiguration support. #526
PR #382: Added spring-boot autoconfiguration support. #526
Conversation
Fixes PR#382 - Spring boot autoconfiguration module added. - Spring boot starter module added. - Added some integration tests for checking Dozer autoconfiguration. - Test logging set to "WARN" when tests runs using 'maven-surefire-plugin'. It increases logs readability.
|
||
<name>Spring Boot AutoConfiguration :: Dozer AutoConfiguration</name> | ||
|
||
<properties> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These properties shouldn't be needed, as provided by dozer-parent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-configuration-processor</artifactId> | ||
<optional>true</optional> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spring boot documentation recommends to do like this. I think this is just for exclude transitive dependency from spring-boot-configuration-processor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-logging</artifactId> | ||
</dependency> | ||
<dependency> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
junit is added by dozer-parent, so can be removed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
</dependency> | ||
</dependencies> | ||
|
||
<build> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as others, dozer-parent adds surefire.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.github.dozermapper.autoconfigure; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you update package to include springboot in name. i.e.: com.github.dozermapper.springboot.autoconfigure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>dozer-spring-boot-auto-configuration</artifactId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you just switch the order, i.e.: groupid and then artifact
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>dozer-spring-boot-auto-configuration</artifactId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you just switch the order, i.e.: groupid and then artifact
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, sure.
<groupId>com.github.dozermapper</groupId> | ||
<artifactId>dozer-spring</artifactId> | ||
<version>${project.version}</version> | ||
<optional>true</optional> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whys this optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because spring boot documentation recommends to do like this just to remove transitive dependencies. It is not an auto-configuration module's responsibility to provide needed libraries. It is up to the project dependencies. If there is no proper dependency autoconfiguration will be just ignored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree that providing dependencies is not a responsibility of autoconfiguration. But it is of the starter, the same documentation states:
The starter module that provides a dependency to the autoconfigure module as well as the library and any additional dependencies that are typically useful. In a nutshell, adding the starter should be enough to start using that library.
...
Its only purpose is to provide the necessary dependencies to work with the library; see it as an opinionated view of what is required to get started.
Thus I would recommend to include autoconfiguration and dozer-spring as compile-time dependencies to the starter module.
And then I would also switch dependencies in autoconfiguration module from optional
to provided
, because optional
has different semantic in Maven, basically meaning "dependencies required by optional feature", while autoconfiguration will not work at all unless Dozer library is provided.
<groupId>com.github.dozermapper</groupId> | ||
<artifactId>dozer-core</artifactId> | ||
<version>${project.version}</version> | ||
<optional>true</optional> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whys this optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see explanation in previous comment.
@@ -81,6 +81,7 @@ | |||
<module>spring</module> | |||
<module>proto</module> | |||
<module>tests</module> | |||
<module>dozer-spring-boot-auto-configuration</module> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be renamed to: spring-boot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call it dozer-spring-boot
just to have clear relation between module folder name and module name.
Actually, I would do the same with dozer-spring
module. Having dozer-spring
module in spring
folder a little bit confusing :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also appreciate having folder names the same as module names.
In addition, to me the perfect structure of Spring-related modules would be like this:
dozer
|- dozer-spring-support (currently does not exist, aggregate module)
| |- dozer-spring (existing module from spring folder)
| |- dozer-spring-boot-starter (newly introduced module)
| |- dozer-spring-boot-autoconfigure (newly introduced module)
|- ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd suggest to change the structure as suggested by @orange-buffalo to another PR, and keep this focused on boot.
@vadeg ; have added some comments. nothing major. @orange-buffalo ; have you guys started using springboot? any comments welcome. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@garethahealy not yet, but we have some plans to move from OSGi to spring-boot based services.
I have added my comments to the review.
plugins-parent/pom.xml
Outdated
@@ -289,6 +289,9 @@ | |||
<excludes> | |||
<exclude>**/Test*.java</exclude> | |||
</excludes> | |||
<systemPropertyVariables> | |||
<org.slf4j.simpleLogger.defaultLogLevel>WARN</org.slf4j.simpleLogger.defaultLogLevel> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imho, this change is too strong. I would say that running tests with Info level is okay and often useful. If there is a need to disable info output for some particular tests, this should be done on per-test or at least per-module basis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, but I think log output should be more accurate. Even Travis-CI complaining that log is too long.
@@ -81,6 +81,7 @@ | |||
<module>spring</module> | |||
<module>proto</module> | |||
<module>tests</module> | |||
<module>dozer-spring-boot-auto-configuration</module> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also appreciate having folder names the same as module names.
In addition, to me the perfect structure of Spring-related modules would be like this:
dozer
|- dozer-spring-support (currently does not exist, aggregate module)
| |- dozer-spring (existing module from spring folder)
| |- dozer-spring-boot-starter (newly introduced module)
| |- dozer-spring-boot-autoconfigure (newly introduced module)
|- ...
public class DozerAutoConfiguration { | ||
|
||
@Autowired | ||
private DozerConfigurationProperties configurationProperties; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend to replace field injection with the constructor injection (actually, this is a recommendation by Spring Team).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed
<groupId>com.github.dozermapper</groupId> | ||
<artifactId>dozer-spring</artifactId> | ||
<version>${project.version}</version> | ||
<optional>true</optional> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree that providing dependencies is not a responsibility of autoconfiguration. But it is of the starter, the same documentation states:
The starter module that provides a dependency to the autoconfigure module as well as the library and any additional dependencies that are typically useful. In a nutshell, adding the starter should be enough to start using that library.
...
Its only purpose is to provide the necessary dependencies to work with the library; see it as an opinionated view of what is required to get started.
Thus I would recommend to include autoconfiguration and dozer-spring as compile-time dependencies to the starter module.
And then I would also switch dependencies in autoconfiguration module from optional
to provided
, because optional
has different semantic in Maven, basically meaning "dependencies required by optional feature", while autoconfiguration will not work at all unless Dozer library is provided.
@ConfigurationProperties(prefix = "dozer") | ||
public class DozerConfigurationProperties { | ||
|
||
private Resource[] mappingFiles = new Resource[] {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have a javadoc on this field (and maybe event skipping javadocs for getter and setter, to avoid unnecessary duplication).
The reason to have a javadoc on the field is to generate a better meta-data file to help IDE to provide richer support for these properties, compare currently generated file
"properties": [
{
"sourceType": "com.github.dozermapper.springboot.autoconfigure.DozerConfigurationProperties",
"defaultValue": [],
"name": "dozer.mapping-files",
"type": "org.springframework.core.io.Resource[]"
}
]
to the one if field has a javadoc:
"properties": [
{
"sourceType": "com.github.dozermapper.springboot.autoconfigure.DozerConfigurationProperties",
"defaultValue": [],
"name": "dozer.mapping-files",
"description": "Mapping files configuration.\n For example <code>classpath:*.dozer.xml<\/code>.",
"type": "org.springframework.core.io.Resource[]"
}
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. But to avoid unnecessary duplication maven-checkstyle-plugin
configuration should be updated. Are you fine with that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I do not see any problems in tuning tools to suite the project needs. In this particular case I would recommend to use @SuppressWarnings("checkstyle:xxx")
in code + enabling SuppressWarningsFilter in CheckStyle config.
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-autoconfigure</artifactId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't all Spring dependencies be provided
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made all of them optional
.
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-dependencies</artifactId> | ||
<version>1.5.8.RELEASE</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably it makes sense to extract this version to a property in bom-dependencies/pom.xml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It did not not work. It will work only in case if bom-dependencies
is a direct parent of dozer-spring-boot-auto-configuration
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for misleading comment, it's not only about the property, but also about the dependency itself.
I.e. if we define in bom-dependencies/pom.xml
:
<dependencyManagement>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
And then in dozer-spring-boot-auto-configuration/pom.xml
define just:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
</dependency>
It should work fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. That make sense.
@orange-buffalo For somehow reason I can not reply to comment.
I think Foe example spring-boot-autoconfigure module marks all dependencies as So would leave as
|
@vadeg frankly speaking, I believe neither |
@orange-buffalo unfortunately, we are not using Gradle (yet). In this case I would stick with |
DozerBeanMapperFactoryBean factoryBean = new DozerBeanMapperFactoryBean(); | ||
factoryBean.setMappingFiles(configurationProperties.getMappingFiles()); | ||
factoryBean.setApplicationContext(applicationContext); | ||
return factoryBean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering if the Mapper instance should be returned, instead of the spring factory. Or does spring wire together the Mapper by its "magic" :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FactoryBean
should be returned. @Bean
annotation has the same semantics as <bean>
xml tag. The following steps are executed by spring itself.
BTW I have removed ApplicationContext
from DozerAutoConfiguration
because DozerBeanMapperFactoryBean
implements ApplicationContextAware
. That means it is not necessary to call factoryBean.setApplicationContext()
because it will be injected by spring itself into DozerBeanMapperFactoryBean
instance.
b9a6ecf
to
ff62844
Compare
@garethahealy @orange-buffalo any updates on this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vadeg from my side the only comment left is about the spring-boot version definition - I would really appreciate if it was in dozer-bom-dependencies
. The rest looks good to me.
<artifactId>dozer-spring-boot-autoconfigure</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>Spring Boot AutoConfiguration :: Dozer AutoConfiguration</name> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update name to match other modules, i.e.: Dozer :: Module :: Sub Module
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>dozer-spring-boot-starter</artifactId> | ||
<name>Spring Boot AutoConfiguration :: Dozer Starter</name> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as other comment. Match other names
Just added a minor comment. But think everything looks fine. Any further comments @orange-buffalo ? |
Nothing from my side, looks good to me. |
d4a215c
to
f015d77
Compare
[PR #382] : Spring boot autoconfiguration support.
maven-surefire-plugin
. It increases logs readability.Issue link
Purpose
Provide spring-boot autoconfiguration support for Dozer.
Approach
Simplifies Dozer configuration when using
spring-boot
framework.Open Questions and Pre-Merge TODOs