Error injecting constructor

95 views
Skip to first unread message

Marcelo Luiz Brocardo

unread,
Sep 6, 2019, 4:47:52 PM9/6/19
to Gsb4j
I include the version 1.0.4 in a Spring project and I'm getting the following error:

any thought?
Thanks in advanced.

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.

2019-09-06 17:45:45.143 ERROR 54523 --- [           main] o.s.boot.SpringApplication               : Application startup failed


org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'safeBrowsingController': Injection of autowired dependencies failed; nested exception is com.google.inject.CreationException: Unable to create injector, see the following errors:


1) Error injecting constructor, java.lang.NullPointerException

  at kg.net.bazi.gsb4j.properties.Gsb4jClientInfoProvider.<init>(Gsb4jClientInfoProvider.java:40)

  at kg.net.bazi.gsb4j.properties.Gsb4jClientInfoProvider.class(Gsb4jClientInfoProvider.java:40)

  while locating kg.net.bazi.gsb4j.properties.Gsb4jClientInfoProvider


1 error

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372) ~[spring-beans-4.3.14.RELEASE.jar!/:4.3.14.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.14.RELEASE.jar!/:4.3.14.RELEASE]

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

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

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.14.RELEASE.jar!/:4.3.14.RELEASE]

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.14.RELEASE.jar!/:4.3.14.RELEASE]

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

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

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.14.RELEASE.jar!/:4.3.14.RELEASE]

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.14.RELEASE.jar!/:4.3.14.RELEASE]

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.14.RELEASE.jar!/:4.3.14.RELEASE]

at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.10.RELEASE.jar!/:1.5.10.RELEASE]

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.10.RELEASE.jar!/:1.5.10.RELEASE]

at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.10.RELEASE.jar!/:1.5.10.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.10.RELEASE.jar!/:1.5.10.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.10.RELEASE.jar!/:1.5.10.RELEASE]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.10.RELEASE.jar!/:1.5.10.RELEASE]

at com.emailveritas.blacklist.BlackListApplication.main(BlackListApplication.java:11) [classes!/:0.0.1-SNAPSHOT]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_101]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101]

at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101]

at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [emailveritas-black-list-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]

at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [emailveritas-black-list-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]

at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [emailveritas-black-list-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]

at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [emailveritas-black-list-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]

Caused by: com.google.inject.CreationException: Unable to create injector, see the following errors:


1) Error injecting constructor, java.lang.NullPointerException

  at kg.net.bazi.gsb4j.properties.Gsb4jClientInfoProvider.<init>(Gsb4jClientInfoProvider.java:40)

  at kg.net.bazi.gsb4j.properties.Gsb4jClientInfoProvider.class(Gsb4jClientInfoProvider.java:40)

  while locating kg.net.bazi.gsb4j.properties.Gsb4jClientInfoProvider


1 error

at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:543) ~[guice-4.2.2.jar!/:na]

at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:186) ~[guice-4.2.2.jar!/:na]

at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:109) ~[guice-4.2.2.jar!/:na]

at com.google.inject.Guice.createInjector(Guice.java:87) ~[guice-4.2.2.jar!/:na]

at kg.net.bazi.gsb4j.Gsb4j.bootstrap(Gsb4j.java:109) ~[gsb4j-core-1.0.4.jar!/:na]

at com.emailveritas.blacklist.controller.SafeBrowsingController.gsb(SafeBrowsingController.java:29) ~[classes!/:0.0.1-SNAPSHOT]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_101]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101]

at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101]

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:701) ~[spring-beans-4.3.14.RELEASE.jar!/:4.3.14.RELEASE]

at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.14.RELEASE.jar!/:4.3.14.RELEASE]

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.14.RELEASE.jar!/:4.3.14.RELEASE]

... 25 common frames omitted

Caused by: java.lang.NullPointerException: null

at java.util.Properties$LineReader.readLine(Properties.java:434) ~[na:1.8.0_101]

at java.util.Properties.load0(Properties.java:353) ~[na:1.8.0_101]

at java.util.Properties.load(Properties.java:341) ~[na:1.8.0_101]

at kg.net.bazi.gsb4j.properties.Gsb4jClientInfoProvider.<init>(Gsb4jClientInfoProvider.java:43) ~[gsb4j-core-1.0.4.jar!/:na]

at kg.net.bazi.gsb4j.properties.Gsb4jClientInfoProvider$$FastClassByGuice$$977c5e3a.newInstance(<generated>) ~[gsb4j-core-1.0.4.jar!/:na]

at com.google.inject.internal.DefaultConstructionProxyFactory$FastClassProxy.newInstance(DefaultConstructionProxyFactory.java:89) ~[guice-4.2.2.jar!/:na]

at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:114) ~[guice-4.2.2.jar!/:na]

at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:91) ~[guice-4.2.2.jar!/:na]

at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:306) ~[guice-4.2.2.jar!/:na]

at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40) ~[guice-4.2.2.jar!/:na]

at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:168) ~[guice-4.2.2.jar!/:na]

at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:39) ~[guice-4.2.2.jar!/:na]

at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:211) ~[guice-4.2.2.jar!/:na]

at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:182) ~[guice-4.2.2.jar!/:na]

... 36 common frames omitted

Azilet Beishenaliev

unread,
Sep 6, 2019, 5:55:13 PM9/6/19
to gs...@googlegroups.com
Hi Marcelo,

Firstly, I have to say that I never used Gsb4j in a Spring project. So, to be honest, I can not propose possible workarounds at this time without further investigation.
I can see what causes the exception -- system class loader can not locate resource file "client-info.properties" that is bundled in gsb4j-core jar.
Seems class loader of your Spring app does not see resources bundled in Gsb4j jars.

Let me have a further investigation on this.

In the meantime, it would be very helpful to have a little more details on how you are integrating Gsb4j in a Spring project.

Regards,
Azilet

Marcelo Luiz Brocardo

unread,
Sep 6, 2019, 6:46:43 PM9/6/19
to Gsb4j
I'm following the instructions to call Gsb4j only once by the following code

@Autowired

private void gsb() {

Properties properties = new Properties();

        properties.setProperty("api.key", "AIxxxxxxxxx...."); 

this.gsb4j =  Gsb4j.bootstrap(properties); 

        this.api = gsb4j.getApiClient(SafeBrowsingApi.Type.LOOKUP_API);

}


In the Eclipse is working fine and I did a debug and the file is being read correctly from the gsb4j jar file.

The problem occurs to run my .jar in a command line.  
I tried to put "client-info.properties" in the properties' path of my project but didn't work also.

Regards,
Marcelo

Azilet Beishenaliev

unread,
Sep 16, 2019, 3:35:51 PM9/16/19
to Gsb4j
Hey Marcelo,

I think your problem is simply a missing Gsb4j jar in your classpath when running in command line.
Eclipse does it automatically for you -- it includes all dependencies in classpath while running the app.

I would suggest you trying to create a "fat jar" to be run in command line. Fat jar is basically your app with all its dependencies bundled in one jar.
Good starting point would be this tutorial or any other one describing fat jar generation.

Sorry for my late response. I hope above helps you to be able to run your app in command line.

Regards,
A

Marcelo Luiz Brocardo

unread,
Sep 17, 2019, 7:01:58 AM9/17/19
to Azilet Beishenaliev, Gsb4j
Hi Azilet,

I’m using POM and it should be done automatically or doesn’t?

Anyway,  I’ll try it, thanks

- - - 
Regards,
________________________________
Marcelo



-- 
You received this message because you are subscribed to the Google Groups "Gsb4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gsb4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gsb4j/e5117271-fbfe-4f4a-9ebf-ad8b5f8c492b%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages