Skip to content
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

Polishing code on dozer-spring-boot-autoconfigure #655

Conversation

kazuki43zoo
Copy link
Contributor

@kazuki43zoo kazuki43zoo commented Jun 16, 2018

Purpose

I've polished some codes on dozer-spring-boot-autoconfigure.

  • Remove @Autowired from constructor

Open Questions and Pre-Merge TODOs

  • Issue created
  • Unit tests pass
  • Documentation updated
  • Travis build passed

@garethahealy
Copy link
Collaborator

garethahealy commented Jun 16, 2018

@kazuki43zoo ; but why have you removed it? if its not needed, please explain why.

CC @vadeg

@kazuki43zoo
Copy link
Contributor Author

kazuki43zoo commented Jun 16, 2018

Since Spring 4.3+ (Spring Boot 1.4+) , It is no longer necessary to specify the @Autowired annotation if the target bean only defines one constructor.
As actually, AutoConfiguration classes provided by Spring Boot uses constructor injection without @Autowired.

WDYT?

@garethahealy
Copy link
Collaborator

garethahealy commented Jun 16, 2018

@kazuki43zoo ; OK. The dozer bits are not strictly tied to a spring4 version, so if the end user wanted to use spring 4.0.0, they could. We only test the bits against the latest spring4 version.

So with that in mind, i'd prefer not to change this as it might break things for people without them realising.

@kazuki43zoo
Copy link
Contributor Author

kazuki43zoo commented Jun 16, 2018

@garethahealy
I've created a demo application using dozer 6.2.0 on Spring Boot 1.3.8.RELEASE(Spring 4.2.8.RELEASE) .

package com.example.dozerdemo;

import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class DozerDemoApplication {

	@Autowired
	Mapper mapper;

	public static void main(String[] args) {
		SpringApplication.run(DozerDemoApplication.class, args);
	}

	@Bean
	CommandLineRunner run() {
		return __ -> System.out.println(mapper);
	}
}

Unfortunately, it does not work. In other words, the dozer-spring-boot-autoconfigure depends on feature of Spring Boot 1.4+(Spring 4.3+). Hence; I think you can accept this change. WDYT?

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.3.8.RELEASE)

2018-06-16 22:10:45.638  INFO 67547 --- [           main] c.e.dozerdemo.DozerDemoApplication       : Starting DozerDemoApplication on xxx.local with PID 67547 (/Users/xxx/git-me/dozer-demo/target/classes started by xxx in /Users/xxx/git-me/dozer-demo)
2018-06-16 22:10:45.646  INFO 67547 --- [           main] c.e.dozerdemo.DozerDemoApplication       : No active profile set, falling back to default profiles: default
2018-06-16 22:10:45.689  INFO 67547 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@4e41089d: startup date [Sat Jun 16 22:10:45 JST 2018]; root of context hierarchy
2018-06-16 22:10:46.265  WARN 67547 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dozerDemoApplication': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.dozer.Mapper com.example.dozerdemo.DozerDemoApplication.mapper; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.github.dozermapper.springboot.autoconfigure.DozerAutoConfiguration': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.dozermapper.springboot.autoconfigure.DozerAutoConfiguration$$EnhancerBySpringCGLIB$$de69aaab]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.github.dozermapper.springboot.autoconfigure.DozerAutoConfiguration$$EnhancerBySpringCGLIB$$de69aaab.<init>()
2018-06-16 22:10:46.274 ERROR 67547 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dozerDemoApplication': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.dozer.Mapper com.example.dozerdemo.DozerDemoApplication.mapper; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.github.dozermapper.springboot.autoconfigure.DozerAutoConfiguration': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.dozermapper.springboot.autoconfigure.DozerAutoConfiguration$$EnhancerBySpringCGLIB$$de69aaab]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.github.dozermapper.springboot.autoconfigure.DozerAutoConfiguration$$EnhancerBySpringCGLIB$$de69aaab.<init>()
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.2.8.RELEASE.jar:4.2.8.RELEASE]
...

NOTE:

Spring Boot 1.4+ work fine as follow:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.0.RELEASE)

2018-06-16 22:21:56.222  INFO 67579 --- [           main] c.e.dozerdemo.DozerDemoApplication       : Starting DozerDemoApplication on xxx.local with PID 67579 (/Users/xxx/git-me/dozer-demo/target/classes started by xxx in /Users/xxx/git-me/dozer-demo)
2018-06-16 22:21:56.224  INFO 67579 --- [           main] c.e.dozerdemo.DozerDemoApplication       : No active profile set, falling back to default profiles: default
2018-06-16 22:21:56.270  INFO 67579 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@6c3f5566: startup date [Sat Jun 16 22:21:56 JST 2018]; root of context hierarchy
2018-06-16 22:21:56.756  INFO 67579 --- [           main] org.dozer.DozerBeanMapperBuilder         : Initializing a new instance of dozer bean mapper.
2018-06-16 22:21:56.757  INFO 67579 --- [           main] org.dozer.util.RuntimeUtils              : OSGi support is false
2018-06-16 22:21:56.760  INFO 67579 --- [           main] o.d.c.r.LegacyPropertiesSettingsResolver : Trying to find Dozer configuration file: dozer.properties
2018-06-16 22:21:56.763  INFO 67579 --- [           main] o.d.c.r.LegacyPropertiesSettingsResolver : Failed to find dozer.properties via org.dozer.config.resolvers.LegacyPropertiesSettingsResolver.
2018-06-16 22:21:56.764  WARN 67579 --- [           main] org.dozer.el.ELExpressionFactory         : javax.el is not supported; Failed to resolve ExpressionFactory, com.sun.el.ExpressionFactoryImpl
2018-06-16 22:21:56.783  INFO 67579 --- [           main] org.dozer.DozerInitializer               : Initializing Dozer. Version: 6.2.0, Thread Name: main
2018-06-16 22:21:56.885  INFO 67579 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
org.dozer.DozerBeanMapper@4032d386
2018-06-16 22:21:56.895  INFO 67579 --- [           main] c.e.dozerdemo.DozerDemoApplication       : Started DozerDemoApplication in 0.983 seconds (JVM running for 1.917)
2018-06-16 22:21:56.895  INFO 67579 --- [       Thread-3] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@6c3f5566: startup date [Sat Jun 16 22:21:56 JST 2018]; root of context hierarchy
2018-06-16 22:21:56.897  INFO 67579 --- [       Thread-3] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown

@garethahealy
Copy link
Collaborator

@kazuki43zoo ; fair comment.

@garethahealy garethahealy merged commit 596a68f into DozerMapper:master Jun 16, 2018
@kazuki43zoo kazuki43zoo deleted the polishing-dozer-spring-boot-autoconfigure branch June 16, 2018 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants