Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website

Mango no longer starting: Error creating bean wit h name 'tokenAuthenticationService'


  • So. Here's a new one.

    I was working on a Mango machine I installed a week ago, and on a reboot Mango started to give me this "springframework.beans.factory.BeanCreationException: Error creating bean with name 'tokenAuthenticationService'" error.

    Originally, I thought maybe my Java was scrambled, so I re installed Java, and I'm running:
    java version "1.8.0_211"
    Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
    Java HotSpot(TM) Client VM (build 25.211-b12, mixed mode)

    Mango fully started fine, but then started tossing this error on it's own, apparently. I installed, it started, I removed some modules, registered GUID, and then reboot the machine. Now it's giving me this every time it starts up.

    I don't want to dump my entire MA.log file, but, well, here's the end of it:

    ERROR 2019-04-19T19:27:23,352 (com.serotonin.m2m2.Main.main:142) - Error during
    initialization
    org.springframework.beans.factory.BeanCreationException: Error creating bean wit
    h name 'tokenAuthenticationService' defined in URL [jar:file:/opt/mango/lib/mang
    o-3.5.6.jar!/com/infiniteautomation/mango/spring/components/TokenAuthenticationS
    ervice.class]: Bean instantiation via constructor failed; nested exception is or
    g.springframework.beans.BeanInstantiationException: Failed to instantiate [com.i
    nfiniteautomation.mango.spring.components.TokenAuthenticationService]: Construct
    or threw exception; nested exception is com.serotonin.ShouldNeverHappenException
    : java.security.spec.InvalidKeySpecException: encoded key spec not recognized: f
    ailed to construct sequence from byte[]: Extra data detected in stream
    at org.springframework.beans.factory.support.ConstructorResolver.autowir
    eConstructor(ConstructorResolver.java:283) ~[spring-beans-5.0.10.RELEASE.jar:5.0
    .10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBean
    Factory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1266) ~[spri
    ng-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBean
    Factory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1123) ~[sprin
    g-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBean
    Factory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans
    -5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBean
    Factory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5
    .0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$
    doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.10.RELEASE.jar:5.0.
    10.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
    y.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.10.RELE
    ASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBe
    an(AbstractBeanFactory.java:315) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEAS
    E]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
    (AbstractBeanFactory.java:199) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.
    preInstantiateSingletons(DefaultListableBeanFactory.java:759) ~[spring-beans-5.0
    .10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finish
    BeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-
    5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refres
    h(AbstractApplicationContext.java:548) ~[spring-context-5.0.10.RELEASE.jar:5.0.1
    0.RELEASE]
    at com.serotonin.m2m2.Lifecycle.springRuntimeContextInitialize(Lifecycle
    .java:407) ~[ma-priv-3.5.6.jar:?]
    at com.serotonin.m2m2.Lifecycle.initialize(Lifecycle.java:311) ~[ma-priv
    -3.5.6.jar:?]
    at com.serotonin.m2m2.Main.main(Main.java:138) ~[ma-priv-3.5.6.jar:?]
    Caused by: org.springframework.beans.BeanInstantiationException: Failed to insta
    ntiate [com.infiniteautomation.mango.spring.components.TokenAuthenticationServic
    e]: Constructor threw exception; nested exception is com.serotonin.ShouldNeverHa
    ppenException: java.security.spec.InvalidKeySpecException: encoded key spec not
    recognized: failed to construct sequence from byte[]: Extra data detected in str
    eam
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:1
    82) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy
    .instantiate(SimpleInstantiationStrategy.java:117) ~[spring-beans-5.0.10.RELEASE
    .jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.autowir
    eConstructor(ConstructorResolver.java:276) ~[spring-beans-5.0.10.RELEASE.jar:5.0
    .10.RELEASE]
    ... 14 more
    Caused by: com.serotonin.ShouldNeverHappenException: java.security.spec.InvalidK
    eySpecException: encoded key spec not recognized: failed to construct sequence f
    rom byte[]: Extra data detected in stream
    at com.infiniteautomation.mango.jwt.JwtSignerVerifier.keysToKeyPair(JwtS
    ignerVerifier.java:160) ~[mango-3.5.6.jar:?]
    at com.infiniteautomation.mango.spring.components.TokenAuthenticationSer
    vice.loadKeyPair(TokenAuthenticationService.java:64) ~[mango-3.5.6.jar:?]
    at com.infiniteautomation.mango.jwt.JwtSignerVerifier.<init>(JwtSignerVe
    rifier.java:55) ~[mango-3.5.6.jar:?]
    at com.infiniteautomation.mango.spring.components.TokenAuthenticationSer
    vice.<init>(TokenAuthenticationService.java:42) ~[mango-3.5.6.jar:?]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    ~[?:1.8.0_211]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
    orAccessorImpl.java:62) ~[?:1.8.0_211]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
    onstructorAccessorImpl.java:45) ~[?:1.8.0_211]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1
    .8.0_211]
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:1
    70) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy
    .instantiate(SimpleInstantiationStrategy.java:117) ~[spring-beans-5.0.10.RELEASE
    .jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.autowir
    eConstructor(ConstructorResolver.java:276) ~[spring-beans-5.0.10.RELEASE.jar:5.0
    .10.RELEASE]
    ... 14 more
    Caused by: java.security.spec.InvalidKeySpecException: encoded key spec not reco
    gnized: failed to construct sequence from byte[]: Extra data detected in stream
    at org.bouncycastle.jcajce.provider.asymmetric.util.BaseKeyFactorySpi.en
    gineGeneratePrivate(Unknown Source) ~[bcprov-jdk15on-1.60.jar:1.60.0]
    at org.bouncycastle.jcajce.provider.asymmetric.ec.KeyFactorySpi.engineGe
    neratePrivate(Unknown Source) ~[bcprov-jdk15on-1.60.jar:1.60.0]
    at java.security.KeyFactory.generatePrivate(KeyFactory.java:366) ~[?:1.8
    .0_211]
    at com.infiniteautomation.mango.jwt.JwtSignerVerifier.keysToKeyPair(JwtS
    ignerVerifier.java:157) ~[mango-3.5.6.jar:?]
    at com.infiniteautomation.mango.spring.components.TokenAuthenticationSer
    vice.loadKeyPair(TokenAuthenticationService.java:64) ~[mango-3.5.6.jar:?]
    at com.infiniteautomation.mango.jwt.JwtSignerVerifier.<init>(JwtSignerVe
    rifier.java:55) ~[mango-3.5.6.jar:?]
    at com.infiniteautomation.mango.spring.components.TokenAuthenticationSer
    vice.<init>(TokenAuthenticationService.java:42) ~[mango-3.5.6.jar:?]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    ~[?:1.8.0_211]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
    orAccessorImpl.java:62) ~[?:1.8.0_211]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
    onstructorAccessorImpl.java:45) ~[?:1.8.0_211]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1
    .8.0_211]
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:1
    70) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy
    .instantiate(SimpleInstantiationStrategy.java:117) ~[spring-beans-5.0.10.RELEASE
    .jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.autowir
    eConstructor(ConstructorResolver.java:276) ~[spring-beans-5.0.10.RELEASE.jar:5.0
    .10.RELEASE]
    ... 14 more
    INFO 2019-04-19T19:27:23,352 (com.serotonin.m2m2.Lifecycle.terminate:422) - Man
    go Lifecycle terminating...
    INFO 2019-04-19T19:27:23,816 (com.serotonin.m2m2.Lifecycle.terminate:571) - Man
    go Lifecycle terminated.


  • @turbo Just re-installed Mango again, and am going through uploading my config.. So far, no errors, and we seem to be OK.

    This one just came out of the blue, though, so I dunno. I'll let the thread know what I figure out about this.


  • Ok.

    Just did this again. I imported a config that I have running on another machine, and.. Crash, with the same error code.

    I'm going to go ahead and try importing one device at a time.

    All the data points added fine, with no error: This install does have the persistent publisher mapped, but not licensed (although it shoudl be-- I've emailed to get my license fxied abotu that).

    The last error message visible is "Initializing H2 connection manager".

    Just before it crashed this time, I was getting error 500's on opening point details when I tried to check the import.


  • Ok.

    I've figured this bit out-- Apparently, if you try and import a configuration with the persistent publisher enabled, that seems to cause the errors I was seeing. So, if you get a problem with this, try importing your configs but without the persistent publisher.


  • Hi Turbo,

    Thanks for reporting the resolution! Also in your email you said part of the issue was that the instance was licensed as free, so the persistent publisher was not licensed. Still, it should not prevent startup and such, so that you for bringing it to our attention and I'll see what we can make better from this angle on this issue.


  • Can you email in the JSON you were trying? Or, was it a database restore? I imported an enabled persistent publisher in 3.5.6 and saw.

    0_1555966396509_properlyLicensedCore.png


  • I'm not sure what the Persistent TCP publisher has to do with the error you are seeing. It seems to me that one of the system settings jwt.userAuth.publicKey or jwt.userAuth.privateKey were not imported correctly.