NutzCN Logo
精华 SpringBoot jar 使用SpringResourceLoaction后还是找不到资源
发布于 196天前 作者 firenut 262 次浏览 复制 上一个帖子 下一个帖子
标签:

Dao 配置

@Configuration
@Repository("dao")
public class GFDao extends NutDao {

    @Autowired
    private FireIdGenerator fireIdGenerator;

    private DataSource hikariDataSource;

    private FileSqlManager fileSqlManager;


    @PostConstruct
    public void reg(){
        CustomMake.me().register(Const.ID_GEN_DEF, fireIdGenerator);
    }


    @Autowired
    public void setHikariDataSource(DataSource hikariDataSource) {
        this.hikariDataSource = hikariDataSource;
        setDataSource(hikariDataSource);
    }


    @Autowired
    private ApplicationContext applicationContext;


    @Autowired
    public void setFileSqlManager() {
        try {

            SpringResourceLoaction springResourceLoaction = new SpringResourceLoaction();
            springResourceLoaction.setApplicationContext(applicationContext);
            Scans.me().addResourceLocation(springResourceLoaction);

            setSqlManager(new FileSqlManager("sqls"));


        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}

异常信息

2017-05-09 12:58:31.220 DEBUG 76723 --- [           main] org.nutz.dao.impl.FileSqlManager         : load >> sqls from root=sqls
2017-05-09 12:58:31.221 DEBUG 76723 --- [           main] org.nutz.dao.impl.FileSqlManager         : load 0 sql >> sqls from root=sqls
2017-05-09 12:58:31.221 DEBUG 76723 --- [           main] org.nutz.dao.impl.DaoSupport             : SqlManager Sql count=0
2017-05-09 12:58:31.372  WARN 76723 --- [           main] org.nutz.conf.NutConf                    : Fail to load config?! for NutzDefaultConfig.js

java.lang.RuntimeException: java.io.FileNotFoundException: file:/Users/firenut/project/gf/gfapp-2-0-api/target/gfAppServer-1.0.jar!/BOOT-INF/lib/nutz-1.r.61.jar!/org/nutz/conf/NutzDefaultConfig.js
  at org.nutz.lang.Lang.wrapThrow(Lang.java:184)
  at org.nutz.lang.Streams.fileIn(Streams.java:509)
  at org.nutz.resource.impl.FileResource.getInputStream(FileResource.java:49)
  at org.nutz.resource.NutResource.getReader(NutResource.java:41)
  at org.nutz.conf.NutConf.loadResource(NutConf.java:88)
  at org.nutz.conf.NutConf.<init>(NutConf.java:63)
  at org.nutz.conf.NutConf.me(NutConf.java:55)
  at org.nutz.conf.NutConf.get(NutConf.java:120)
  at org.nutz.el.opt.custom.CustomMake.init(CustomMake.java:36)
  at org.nutz.el.opt.custom.CustomMake.<clinit>(CustomMake.java:28)
  at cn.gf.common.db.GFDao.reg(GFDao.java:177)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:483)
  at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:366)
  at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:311)
  at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:134)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1620)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
  at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
  at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
  at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
  at cn.gf.gfAppServer.main(gfAppServer.java:28)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:483)
  at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
  at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
  at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
  at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.io.FileNotFoundException: file:/Users/firenut/project/gf/gfapp-2-0-api/target/gfAppServer-1.0.jar!/BOOT-INF/lib/nutz-1.r.61.jar!/org/nutz/conf/NutzDefaultConfig.js
  at org.nutz.lang.Streams._input(Streams.java:680)
  at org.nutz.lang.Streams.fileIn(Streams.java:506)
  ... 40 common frames omitted
14 回复

换最新快照版

@wendal
我将 NutConf 在我的工程里面建了一个包 org.nutz.conf 并把 NutConf copy 了进去。 打jar 包后 不提示找不到了 但是也没有加在sql ,log 看到的sql count 是 0 ,然后我尝试访问查询 也提示 Caused by: org.nutz.dao.SqlNotFoundException: fail to find SQL 'bid.selectBidProducts'!

日志贴一下

另外,sql文件放哪里了呢?

@wendal
sql 文件放在了 resources 目录下 的 sqls 文件夹内

log

2017-05-09 14:19:52.883  INFO 77105 --- [           main] org.nutz.filepool.NutFilePool            : Init file-pool by: /Users/firenut/.nutz/tmp/dao/ [200000]
2017-05-09 14:19:52.885  INFO 77105 --- [           main] org.nutz.filepool.NutFilePool            : file-pool.cursor: 0
2017-05-09 14:19:52.996 DEBUG 77105 --- [           main] org.nutz.dao.jdbc.Jdbcs                  : Jdbcs init complete
2017-05-09 14:19:52.997  INFO 77105 --- [           main] org.nutz.dao.jdbc.Jdbcs                  : Get Connection from DataSource for JdbcExpert, if you lock at here, check your database server and configure
2017-05-09 14:19:53.007  INFO 77105 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2017-05-09 14:19:53.463  INFO 77105 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2017-05-09 14:19:53.475 DEBUG 77105 --- [           main] org.nutz.dao.impl.DaoSupport             : select expert : org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert
2017-05-09 14:19:53.495 DEBUG 77105 --- [           main] org.nutz.dao.impl.DaoSupport             : JDBC Driver --> mysql-connector-java-5.1.41 ( Revision: 83c6dc41b96809df81444362933043b20a1d49d5 )
2017-05-09 14:19:53.495 DEBUG 77105 --- [           main] org.nutz.dao.impl.DaoSupport             : JDBC Name   --> MySQL Connector Java
2017-05-09 14:19:53.495 DEBUG 77105 --- [           main] org.nutz.dao.impl.DaoSupport             : JDBC URL    --> jdbc:mysql://10.0.0.254/gf-0509
2017-05-09 14:19:53.510 DEBUG 77105 --- [           main] o.n.dao.impl.jdbc.mysql.MysqlJdbcExpert  : Mysql : character_set_client=utf8mb4
2017-05-09 14:19:53.510 DEBUG 77105 --- [           main] o.n.dao.impl.jdbc.mysql.MysqlJdbcExpert  : Mysql : character_set_connection=utf8mb4
2017-05-09 14:19:53.510 DEBUG 77105 --- [           main] o.n.dao.impl.jdbc.mysql.MysqlJdbcExpert  : Mysql : character_set_database=utf8mb4
2017-05-09 14:19:53.510 DEBUG 77105 --- [           main] o.n.dao.impl.jdbc.mysql.MysqlJdbcExpert  : Mysql : character_set_filesystem=binary
2017-05-09 14:19:53.511 DEBUG 77105 --- [           main] o.n.dao.impl.jdbc.mysql.MysqlJdbcExpert  : Mysql : character_set_results=
2017-05-09 14:19:53.511 DEBUG 77105 --- [           main] o.n.dao.impl.jdbc.mysql.MysqlJdbcExpert  : Mysql : character_set_server=utf8mb4
2017-05-09 14:19:53.511 DEBUG 77105 --- [           main] o.n.dao.impl.jdbc.mysql.MysqlJdbcExpert  : Mysql : character_set_system=utf8
2017-05-09 14:19:53.511 DEBUG 77105 --- [           main] o.n.dao.impl.jdbc.mysql.MysqlJdbcExpert  : Mysql : character_sets_dir=/usr/share/mysql/charsets/
2017-05-09 14:19:53.514 DEBUG 77105 --- [           main] o.n.dao.impl.jdbc.mysql.MysqlJdbcExpert  : Mysql : binlog_format=STATEMENT
2017-05-09 14:19:53.515 DEBUG 77105 --- [           main] o.n.dao.impl.jdbc.mysql.MysqlJdbcExpert  : Mysql : database=gf-0509
2017-05-09 14:19:53.517 DEBUG 77105 --- [           main] o.n.dao.impl.jdbc.mysql.MysqlJdbcExpert  : Mysql : user=root@10.0.0.222
2017-05-09 14:19:53.549 DEBUG 77105 --- [           main] org.nutz.dao.impl.DaoSupport             : Database info --> MYSQL:[MySQL - 5.6.29]
2017-05-09 14:20:10.928 DEBUG 77105 --- [           main] org.nutz.dao.impl.FileSqlManager         : load >> sqls from root=sqls
2017-05-09 14:20:10.929 DEBUG 77105 --- [           main] org.nutz.dao.impl.FileSqlManager         : load 0 sql >> sqls from root=sqls
2017-05-09 14:20:10.929 DEBUG 77105 --- [           main] org.nutz.dao.impl.DaoSupport             : SqlManager Sql count=0
2017-05-09 14:20:12.581  INFO 77105 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService  'taskExecutor'
2017-05-09 14:20:14.200 DEBUG 77105 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking for request mappings in application

觉得addResourceLocation根本没执行呢?

把addResourceLocation放在setHikariDataSource方法里面试试,打印点日志

我直接idea debug 就都可以load 进来 只要打成jar 就 load不进来

@wendal
确实是先 set的location 在 setFileSqlManager 日志打印

2017-05-09 14:36:52.386 DEBUG 77242 --- [           main] org.nutz.dao.impl.DaoSupport             : SqlManager Sql count=0

之前 执行了一段时间 才打印上述日志

额,打包才能重现,然后打包之后没法debug,是这样不?

我比较困惑SpringResourceLoaction为啥找不到,如果能找办法debug或者多点日志也行

另外,确认一下jar里面有无sqls哦

用JD-GUI 查看了一下是有的
Markdown

@wendal
问题找到了
之前

FileSqlManager fileSqlManager = new FileSqlManager("sqls");

然后我看了下 SpringResourceLoaction 的代码 发现

 Resource[] tmp = applicationContext.getResources("classpath*:" + base + "*");

最后我这边改成

FileSqlManager fileSqlManager = new FileSqlManager(" /sqls/");

多谢解答哈

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