NutzCN Logo
问答 关于Spring boot 和Nutz.Dao 请教一个问题!
发布于 2606天前 作者 pontali 2355 次浏览 复制 上一个帖子 下一个帖子
标签:

我的基础框架做了一些封装,会依赖nutz.dao , 但是有些场景是要依赖框架包,但不需要数据库相关操作,如果不配置数据源和nutz.dao 相关配置,就会报一下信息,有没有什么办法不让nutz.dao starter 中的配置起效?

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dao' defined in class path resource [org/nutz/plugin/spring/boot/NutzDaoAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.nutz.dao.Dao]: Factory method 'dao' threw exception; nested exception is java.lang.NullPointerException
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
	at cn.sayyoo.zuul.ZuulApplication.main(ZuulApplication.java:10) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.nutz.dao.Dao]: Factory method 'dao' threw exception; nested exception is java.lang.NullPointerException
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	... 18 common frames omitted
Caused by: java.lang.NullPointerException: null
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:307) ~[na:1.8.0_121]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_121]
	at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:556) ~[druid-1.1.2.jar:1.1.2]
	at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:757) ~[druid-1.1.2.jar:1.1.2]
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1129) ~[druid-1.1.2.jar:1.1.2]
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1125) ~[druid-1.1.2.jar:1.1.2]
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:104) ~[druid-1.1.2.jar:1.1.2]
	at org.nutz.trans.Trans.getConnectionAuto(Trans.java:263) ~[nutz-1.r.63-20171103.015144-135.jar:1.r.63-SNAPSHOT]
	at org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:106) ~[nutz-1.r.63-20171103.015144-135.jar:1.r.63-SNAPSHOT]
	at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:187) ~[nutz-1.r.63-20171103.015144-135.jar:1.r.63-SNAPSHOT]
	at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:178) ~[nutz-1.r.63-20171103.015144-135.jar:1.r.63-SNAPSHOT]
	at org.nutz.dao.impl.NutDao.<init>(NutDao.java:105) ~[nutz-1.r.63-20171103.015144-135.jar:1.r.63-SNAPSHOT]
	at org.nutz.dao.impl.NutDao.<init>(NutDao.java:109) ~[nutz-1.r.63-20171103.015144-135.jar:1.r.63-SNAPSHOT]
	at org.nutz.plugin.spring.boot.NutzDaoAutoConfiguration.dao(NutzDaoAutoConfiguration.java:34) ~[nutz-plugins-spring-boot-starter-1.r.63-SNAPSHOT.jar:na]
	at org.nutz.plugin.spring.boot.NutzDaoAutoConfiguration$$EnhancerBySpringCGLIB$$9fce44d5.CGLIB$dao$0(<generated>) ~[nutz-plugins-spring-boot-starter-1.r.63-SNAPSHOT.jar:na]
	at org.nutz.plugin.spring.boot.NutzDaoAutoConfiguration$$EnhancerBySpringCGLIB$$9fce44d5$$FastClassBySpringCGLIB$$ccf95698.invoke(<generated>) ~[nutz-plugins-spring-boot-starter-1.r.63-SNAPSHOT.jar:na]
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.nutz.plugin.spring.boot.NutzDaoAutoConfiguration$$EnhancerBySpringCGLIB$$9fce44d5.dao(<generated>) ~[nutz-plugins-spring-boot-starter-1.r.63-SNAPSHOT.jar:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	... 19 common frames omitted


Process finished with exit code 1

4 回复

如果不需要使用nutz-dao的starter, 那直接引用nutz.jar嘛

@wendal 自己封装的基础框架包会打成jar,有的项目需要dao,有的不需要。 我想的是不需要dao的时候我的基础框架jar能直接被引用,不受dao配置的限制。

加个enable开关?但spring boot在Applection类有注解禁用某个starter呢

@wendal 好的,刚刚想明白了,其实基础框架直接引用nutz.jar , 需要nutz 的starter 的时候再引用也可以。谢谢!

添加回复
请先登陆
回到顶部