在本地Eclipse开发和调试是没问题的,打包成jar放到Linux下无法启动,报错:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'mainThead' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:277)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
... 17 more

其中“mainThead”是通过 spring的@service注解的(使用@Component)也一样。

这是由于:spring annotion 找不到jar里的类导致NoSuchBeanDefinitionException错误。

解决方法:打包的时候选中”Add directory entries“选项来解决。如下图:

javawind.net