Running production package failed

Hi,

I am using V14 Bakery starter template to create my project. However, when I ran the jar packaged from command “mvn clean package -Pproductin”, it couldn’t run well. If I ran with command “mvn spring-boot:run”, it went very well. Did I miss something when packaging it? PLease kindly advise.

Best regards,
Joey

it couldn’t run well.

Could you describe more what is not working well when you run the application. What are the symptoms? Did you get errors in build process?

Joey Chen:
Hi,

I am using V14 Bakery starter template to create my project. However, when I ran the jar packaged from command “mvn clean package -Pproductin”, it couldn’t run well. If I ran with command “mvn spring-boot:run”, it went very well. Did I miss something when packaging it? PLease kindly advise.

Best regards,
Joey

Make sure, you’ve set production mode to true in your application.properties before your build package.
Sample in your application.properties:

vaadin.productionMode = true

Regards,
Reja

I did make vaadin.productionMode = true in the properties. I packaged into a jar and ran with java -jar [full-path-myapp.jar]
com.company.Application, and I got the errors like:

Caused by: java.lang.NullPointerException
	at com.company.springframework.security.SecurityUtils.getUsername(SecurityUtils.java:54) ~[classes!/:1.0]

	at com.company.springframework.CompanyConfiguration.currentUser(SoftVanguardConfiguration.java:103) ~[classes!/:1.0]

	at com.company.springframework.CompanyConfiguration$$EnhancerBySpringCGLIB$$5ef74195.CGLIB$currentUser$4(<generated>) ~[classes!/:1.0]

	at com.company.springframework.CompanyConfiguration$$EnhancerBySpringCGLIB$$5ef74195$$FastClassBySpringCGLIB$$cd5c09db.invoke(<generated>) ~[classes!/:1.0]

	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at com.company.springframework.CompanyConfiguration$$EnhancerBySpringCGLIB$$5ef74195.currentUser(<generated>) ~[classes!/:1.0]

	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_221]

	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_221]

	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_221]

	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_221]

	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:607) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:338) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1251) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1171) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:218) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1341) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1187) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:305) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

	at com.vaadin.flow.spring.SpringInstantiator.getOrCreate(SpringInstantiator.java:117) ~[vaadin-spring-12.0.6.jar!/:?]

	at com.vaadin.flow.di.Instantiator.createRouteTarget(Instantiator.java:158) ~[flow-server-2.0.14.jar!/:2.0.14]

	at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.lambda$getRouteTarget$1(AbstractNavigationStateRenderer.java:127) ~[flow-server-2.0.14.jar!/:2.0.14]

	at java.util.Optional.orElseGet(Optional.java:267) ~[?:1.8.0_221]

	at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.getRouteTarget(AbstractNavigationStateRenderer.java:126) ~[flow-server-2.0.14.jar!/:2.0.14]

	at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.createChain(AbstractNavigationStateRenderer.java:316) ~[flow-server-2.0.14.jar!/:2.0.14]

	at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.handle(AbstractNavigationStateRenderer.java:195) ~[flow-server-2.0.14.jar!/:2.0.14]

	at com.vaadin.flow.router.internal.ErrorStateRenderer.handle(ErrorStateRenderer.java:51) ~[flow-server-2.0.14.jar!/:2.0.14]

	at com.vaadin.flow.router.Router.handleExceptionNavigation(Router.java:261) ~[flow-server-2.0.14.jar!/:2.0.14]

	at com.vaadin.flow.router.Router.navigate(Router.java:196) ~[flow-server-2.0.14.jar!/:2.0.14]

	at com.vaadin.flow.router.Router.initializeUI(Router.java:92) ~[flow-server-2.0.14.jar!/:2.0.14]

	at com.vaadin.flow.server.BootstrapHandler.createAndInitUI(BootstrapHandler.java:1420) ~[flow-server-2.0.14.jar!/:2.0.14]

	at com.vaadin.flow.server.BootstrapHandler.synchronizedHandleRequest(BootstrapHandler.java:456) ~[flow-server-2.0.14.jar!/:2.0.14]

	at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40) ~[flow-server-2.0.14.jar!/:2.0.14]

	at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1540) ~[flow-server-2.0.14.jar!/:2.0.14]

	at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:246) ~[flow-server-2.0.14.jar!/:2.0.14]

	... 82 more

It seems that bean injection could not be located. I am wondering what I missed in packaging. Please kindly advise.

Best regards,
Joey

Joey Chen:
I did make vaadin.productionMode = true in the properties. I packaged into a jar and ran with java -jar [full-path-myapp.jar]
com.company.Application, and I got the errors like:

Caused by: java.lang.NullPointerException
	at com.company.springframework.security.SecurityUtils.getUsername(SecurityUtils.java:54) ~[classes!/:1.0]

at com.company.springframework.CompanyConfiguration.currentUser(SoftVanguardConfiguration.java:103) ~[classes!/:1.0]

at com.company.springframework.CompanyConfiguration$$EnhancerBySpringCGLIB$$5ef74195.CGLIB$currentUser$4() ~[classes!/:1.0]

at com.company.springframework.CompanyConfiguration$$EnhancerBySpringCGLIB$$5ef74195$$FastClassBySpringCGLIB$$cd5c09db.invoke() ~[classes!/:1.0]

at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at com.company.springframework.CompanyConfiguration$$EnhancerBySpringCGLIB$$5ef74195.currentUser() ~[classes!/:1.0]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_221]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_221]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_221]

at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_221]

at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:607) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:338) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1251) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1171) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:218) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1341) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1187) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:305) ~[spring-beans-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

at com.vaadin.flow.spring.SpringInstantiator.getOrCreate(SpringInstantiator.java:117) ~[vaadin-spring-12.0.6.jar!/:?]

at com.vaadin.flow.di.Instantiator.createRouteTarget(Instantiator.java:158) ~[flow-server-2.0.14.jar!/:2.0.14]

at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.lambda$getRouteTarget$1(AbstractNavigationStateRenderer.java:127) ~[flow-server-2.0.14.jar!/:2.0.14]

at java.util.Optional.orElseGet(Optional.java:267) ~[?:1.8.0_221]

at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.getRouteTarget(AbstractNavigationStateRenderer.java:126) ~[flow-server-2.0.14.jar!/:2.0.14]

at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.createChain(AbstractNavigationStateRenderer.java:316) ~[flow-server-2.0.14.jar!/:2.0.14]

at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.handle(AbstractNavigationStateRenderer.java:195) ~[flow-server-2.0.14.jar!/:2.0.14]

at com.vaadin.flow.router.internal.ErrorStateRenderer.handle(ErrorStateRenderer.java:51) ~[flow-server-2.0.14.jar!/:2.0.14]

at com.vaadin.flow.router.Router.handleExceptionNavigation(Router.java:261) ~[flow-server-2.0.14.jar!/:2.0.14]

at com.vaadin.flow.router.Router.navigate(Router.java:196) ~[flow-server-2.0.14.jar!/:2.0.14]

at com.vaadin.flow.router.Router.initializeUI(Router.java:92) ~[flow-server-2.0.14.jar!/:2.0.14]

at com.vaadin.flow.server.BootstrapHandler.createAndInitUI(BootstrapHandler.java:1420) ~[flow-server-2.0.14.jar!/:2.0.14]

at com.vaadin.flow.server.BootstrapHandler.synchronizedHandleRequest(BootstrapHandler.java:456) ~[flow-server-2.0.14.jar!/:2.0.14]

at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40) ~[flow-server-2.0.14.jar!/:2.0.14]

at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1540) ~[flow-server-2.0.14.jar!/:2.0.14]

at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:246) ~[flow-server-2.0.14.jar!/:2.0.14]

… 82 more

It seems that bean injection could not be located. I am wondering what I missed in packaging. Please kindly advise.

Best regards,
Joey

Hi, sorry for late reply. This issue already solved?

Can you check your SecurityUtils.java line 54. Any wrong code on there ?

Joey Chen:
Hi,

I am using V14 Bakery starter template to create my project. However, when I ran the jar packaged from command “mvn clean package -Pproductin”, it couldn’t run well. If I ran with command “mvn spring-boot:run”, it went very well. Did I miss something when packaging it? PLease kindly advise.

Best regards,
Joey

I think you have typo on there productin should be production

mvn clean package -Pproductin

It seems that something wrong with my codes. It’s fixed now. Thanks a lot.

Joey Chen:
It seems that something wrong with my codes. It’s fixed now. Thanks a lot.

Glad to hear that.

Cheers,
Reja