因存在启动时sql获取问题,按wendal指导说是升级包就可以了,由于我是接手的项目,本身不熟悉java的配置和Bean等。
特请@wendal再给指点指点。
更新前的包
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutz</artifactId>
<version>1.r.61</version>
</dependency>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutz-integration-spring</artifactId>
<version>1.r.61.r2</version>
</dependency>
更新后的包
<!-- ORM ONLY -->
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutz</artifactId>
<version>1.r.66</version>
</dependency>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutz-integration-spring</artifactId>
<version>1.r.66.r2</version>
</dependency>
其他配置代码如下:
import com.zaxxer.hikari.HikariDataSource;
import org.nutz.integration.spring.SpringResourceLoaction;
import org.nutz.resource.Scans;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.annotation.Order;
import javax.sql.DataSource;
@Configuration
@EnableAutoConfiguration
@ConfigurationProperties(prefix = "spring.datasource")
@Order(2)
public class DataSourceConfig {
private String username;
private String password;
private String url;
private String driverClassName;
private String connectionTestQuery;
private int maximumPoolSize;
@Autowired
private PkGenConfig pkGenConfig;
@Autowired
private ApplicationContext applicationContext;
@Bean
@Primary
public DataSource primaryDataSource() {
final HikariDataSource ds = new HikariDataSource();
ds.setDriverClassName(driverClassName);
ds.setJdbcUrl(url);
ds.setUsername(username);
ds.setPassword(password);
ds.setMaximumPoolSize(maximumPoolSize==0?200:maximumPoolSize);
ds.setPoolName(pkGenConfig.getIp());
ds.setConnectionTestQuery(connectionTestQuery);
return ds;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getDriverClassName() {
return driverClassName;
}
public void setDriverClassName(String driverClassName) {
this.driverClassName = driverClassName;
}
public String getConnectionTestQuery() {
return connectionTestQuery;
}
public void setConnectionTestQuery(String connectionTestQuery) {
this.connectionTestQuery = connectionTestQuery;
}
public int getMaximumPoolSize() {
return maximumPoolSize;
}
public void setMaximumPoolSize(int maximumPoolSize) {
this.maximumPoolSize = maximumPoolSize;
}
public ApplicationContext getApplicationContext() {
return applicationContext;
}
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
}
package cn.guanfu.common.db;
import cn.guanfu.common.utils.Utils;
import cn.guanfu.config.PkGenConfig;
import cn.guanfu.entity.SysIdWorkerEntity;
import cn.guanfu.service.SystemService;
import com.relops.snowflake.Snowflake;
import org.nutz.conf.NutConf;
import cn.guanfu.common.constants.Const;
import cn.guanfu.common.generator.FireIdGenerator;
import org.nutz.dao.*;
import org.nutz.dao.entity.Entity;
import org.nutz.dao.entity.Record;
import org.nutz.dao.impl.EntityHolder;
import org.nutz.dao.impl.FileSqlManager;
import org.nutz.dao.impl.NutDao;
import org.nutz.dao.jdbc.JdbcExpert;
import org.nutz.dao.pager.Pager;
import org.nutz.dao.sql.PojoMaker;
import org.nutz.dao.sql.Sql;
import org.nutz.el.opt.custom.CustomMake;
import org.nutz.integration.spring.SpringResourceLoaction;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.lang.Each;
import org.nutz.resource.NutResource;
import org.nutz.resource.Scans;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.stereotype.Repository;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@SuppressWarnings("SpringJavaAutowiringInspection")
@Configuration
@Repository("dao")
@Order(3)
public class GFDao extends NutDao{
// @Autowired
// private PKGenerator pkGenerator;
@Autowired
private FireIdGenerator fireIdGenerator;
@Autowired
private PkGenConfig pkGenConfig;
private DataSource hikariDataSource;
private Integer node;
private FileSqlManager fileSqlManager;
// private static final String[] SQLS = {
// "user.sql",
// "module.sql",
// "system.sql",
// "article.sql"
// };
/**
* 查全部
* @param clazz
* @param sqlName
* @param <T>
* @return
*/
public <T>List<T> getList(Class clazz,String sqlName){
return this.getList(clazz,sqlName,null);
}
/**
* 通过页码查询
* @param clazz
* @param sqlName
* @param pageNumber
* @param <T>
* @return
*/
public <T>List<T> getList(Class clazz,String sqlName,int pageNumber){
return this.getList(clazz,sqlName,null,null,pageNumber);
}
/**
* 通过参数查询
* @param clazz
* @param sqlName
* @param params
* @param pageNumber
* @param <T>
* @return
*/
public <T>List<T> getList(Class clazz, String sqlName, Map params,Map vars, Integer pageNumber){
Pager pager = null;
if(pageNumber != null){
pager = new Pager();
pager.setPageNumber(pageNumber);
pager.setPageSize(15);
}
return this.getPageList(clazz,sqlName,params,vars,pager);
}
public <T>List<T> getList(Class clazz, String sqlName, Map params,Map vars){
return this.getPageList(clazz,sqlName,params,vars,null);
}
/**
*
* @param clazz 返回类型
* @param sqlName sql 名
* @param params 参数
* @param <T> 返回类型
* @return
*/
public <T>List<T> getList(Class clazz, String sqlName, Map params){
return this.getPageList(clazz,sqlName,params,null,null);
}
/**
* 自定义分页查询
* @param clazz
* @param sqlName
* @param params
* @param pager
* @param <T>
* @return
*/
public <T>List<T> getPageList(Class clazz, String sqlName, Map params,Map vars, Pager pager){
Sql sql = this.sqls().create(sqlName);
sql.setCallback(Sqls.callback.entities());
sql.setEntity(this.getEntity(clazz));
if(params != null && params.size() > 0){
sql.params().putAll(params);
}
if(vars != null && vars.size() > 0){
sql.vars().putAll(vars);
}
if(pager != null){
sql.setPager(pager);
}
this.execute(sql);
return sql.getList(clazz);
}
public <T> T getObject(Class<T> clazz,String sqlName){
return this.getObject(clazz,sqlName,null);
}
public <T> T getObject(Class<T> clazz,String sqlName, Map params){
return getObject(clazz,sqlName,params,null);
}
public <T> T getObject(Class<T> clazz,String sqlName, Map params,Map vars){
Sql sql = this.sqls().create(sqlName);
sql.setCallback(Sqls.callback.entities());
sql.setEntity(this.getEntity(clazz));
if(params != null){
sql.params().putAll(params);
}
if(vars != null){
sql.vars().putAll(vars);
}
this.execute(sql);
return sql.getObject(clazz);
}
@PostConstruct
public void reg(){
String ip = pkGenConfig.getIp();
if(ip == null){
this.node = 1024;
}else{
SysIdWorkerEntity sysIdWorkerEntity = this.fetch(SysIdWorkerEntity.class, Cnd.where("ip","=",ip));
if(sysIdWorkerEntity != null){
this.node = sysIdWorkerEntity.getNode();
}else{
sysIdWorkerEntity = insertNewWorker();
this.node = sysIdWorkerEntity.getNode();
}
}
fireIdGenerator.setSnowflake(new Snowflake(this.node));
CustomMake.me().register(Const.ID_GEN_DEF, fireIdGenerator);
}
private SysIdWorkerEntity insertNewWorker(){
SysIdWorkerEntity oldWorker = getObject(SysIdWorkerEntity.class,"sys.fetchMaxNode");
SysIdWorkerEntity sysIdWorkerEntityNew = new SysIdWorkerEntity();
sysIdWorkerEntityNew.setCreateTime(Utils.currentTime());
sysIdWorkerEntityNew.setIp(pkGenConfig.getIp());
sysIdWorkerEntityNew.setNode(oldWorker==null?1:oldWorker.getNode()+1);
try {
this.fastInsert(sysIdWorkerEntityNew);
return sysIdWorkerEntityNew;
}catch (Exception e){
insertNewWorker();
}
return null;
}
@Autowired
public void setHikariDataSource(DataSource hikariDataSource) {
this.hikariDataSource = hikariDataSource;
SpringResourceLoaction springResourceLoaction = new SpringResourceLoaction();
springResourceLoaction.setApplicationContext(applicationContext);
Scans.me().addResourceLocation(springResourceLoaction);
this.setDataSource(hikariDataSource);
}
@Autowired
private ApplicationContext applicationContext;
}
---
现更新包版本之后,报错如下,不太清楚是哪里没有配置好,如果代码没贴全请@wendal明示,这是在我只更新了nutz和nutz-integration-spring包的情况下提示的,其他东西我没有改。
Connected to the target VM, address: '127.0.0.1:52409', transport: 'socket'
10:47:00.503 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
10:47:00.510 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
10:47:00.512 [main] DEBUG org.springframework.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
10:47:00.746 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
10:47:00.746 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/]
10:47:00.747 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/Users/wangchao/java-work/guanfuapp-2-0-api/target/classes/]
10:47:00.754 [restartedMain] DEBUG org.springframework.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
10:47:00.754 [restartedMain] DEBUG org.springframework.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
10:47:00.754 [restartedMain] DEBUG org.springframework.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.6.RELEASE)
2019-04-29 10:47:01.541 INFO 70903 --- [ restartedMain] cn.guanfu.GuanfuAppServer : Starting GuanfuAppServer on wangchaodeMacBook-Pro.local with PID 70903 (/Users/wangchao/java-work/guanfuapp-2-0-api/target/classes started by wangchao in /Users/wangchao/java-work/guanfuapp-2-0-api)
2019-04-29 10:47:01.543 INFO 70903 --- [ restartedMain] cn.guanfu.GuanfuAppServer : The following profiles are active: pkgen,dev
2019-04-29 10:47:01.633 INFO 70903 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@10d3d6d5: startup date [Mon Apr 29 10:47:01 CST 2019]; root of context hierarchy
2019-04-29 10:47:04.138 INFO 70903 --- [ restartedMain] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'managementServletContext' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.actuate.autoconfigure.EndpointWebMvcHypermediaManagementContextConfiguration; factoryMethodName=managementServletContext; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/actuate/autoconfigure/EndpointWebMvcHypermediaManagementContextConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration; factoryMethodName=managementServletContext; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.class]]
2019-04-29 10:47:04.183 INFO 70903 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2019-04-29 10:47:05.352 INFO 70903 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'redisCacheConfig' of type [cn.guanfu.config.RedisCacheConfig$$EnhancerBySpringCGLIB$$c7f22428] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-04-29 10:47:05.462 INFO 70903 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cache.annotation.ProxyCachingConfiguration' of type [org.springframework.cache.annotation.ProxyCachingConfiguration$$EnhancerBySpringCGLIB$$fdf29e8d] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-04-29 10:47:06.072 INFO 70903 --- [ restartedMain] org.xnio : XNIO version 3.3.8.Final
2019-04-29 10:47:06.099 INFO 70903 --- [ restartedMain] org.xnio.nio : XNIO NIO Implementation Version 3.3.8.Final
2019-04-29 10:47:06.295 WARN 70903 --- [ restartedMain] io.undertow.websockets.jsr : UT026009: XNIO worker was not set on WebSocketDeploymentInfo, the default worker will be used
2019-04-29 10:47:06.295 WARN 70903 --- [ restartedMain] io.undertow.websockets.jsr : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2019-04-29 10:47:06.448 INFO 70903 --- [ restartedMain] io.undertow.servlet : Initializing Spring embedded WebApplicationContext
2019-04-29 10:47:06.449 INFO 70903 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 4820 ms
2019-04-29 10:47:06.761 INFO 70903 --- [ restartedMain] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2019-04-29 10:47:06.767 INFO 70903 --- [ restartedMain] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'metricsFilter' to: [/*]
2019-04-29 10:47:06.768 INFO 70903 --- [ restartedMain] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-04-29 10:47:06.768 INFO 70903 --- [ restartedMain] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-04-29 10:47:06.768 INFO 70903 --- [ restartedMain] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2019-04-29 10:47:06.768 INFO 70903 --- [ restartedMain] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2019-04-29 10:47:06.769 INFO 70903 --- [ restartedMain] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webRequestLoggingFilter' to: [/*]
2019-04-29 10:47:06.769 INFO 70903 --- [ restartedMain] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'applicationContextIdFilter' to: [/*]
2019-04-29 10:47:07.167 WARN 70903 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dao': Injection of autowired dependencies failed; nested exception is java.lang.NoSuchFieldError: USE_EL_IN_OBJECT_CONVERT
2019-04-29 10:47:07.184 INFO 70903 --- [ restartedMain] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2019-04-29 10:47:07.194 ERROR 70903 --- [ restartedMain] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dao': Injection of autowired dependencies failed; nested exception is java.lang.NoSuchFieldError: USE_EL_IN_OBJECT_CONVERT
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
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:867)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at cn.guanfu.GuanfuAppServer.main(GuanfuAppServer.java:34)
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:498)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.NoSuchFieldError: USE_EL_IN_OBJECT_CONVERT
at org.nutz.mapl.impl.convert.ObjConvertImpl.<init>(ObjConvertImpl.java:46)
at org.nutz.mapl.Mapl.maplistToObj(Mapl.java:34)
at org.nutz.json.Json.parse(Json.java:94)
at org.nutz.json.Json.fromJson(Json.java:73)
at org.nutz.json.Json.fromJson(Json.java:178)
at org.nutz.lang.Lang.map(Lang.java:1282)
at org.nutz.lang.Strings.<clinit>(Strings.java:1016)
at org.nutz.lang.util.Disks.normalize(Disks.java:298)
at org.nutz.lang.util.Disks.absolute(Disks.java:255)
at org.nutz.lang.Files.findFile(Files.java:465)
at org.nutz.lang.Files.findFile(Files.java:648)
at org.nutz.dao.jdbc.Jdbcs.<clinit>(Jdbcs.java:73)
at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:187)
at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:178)
at cn.guanfu.common.db.GFDao.setHikariDataSource(GFDao.java:274)
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:498)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:701)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
... 20 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:52409', transport: 'socket'
Process finished with exit code 0