各位大神帮我看看哪里有错!我的需求现在是这样的:
默认的时候需要在txt文本数据源中配置一个数据源:默认数据源为test1
configName=mysql1 mysql1_jdbcUrl = jdbc:mysql://127.0.0.1:3306/test1?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull mysql1_user = root mysql1_password = root
当我运行第一个方法的时候调用的是默认数据源中的数据库
然后我再通过java或者手动写入第二个数据源:第二个数据源为test2
configName=mysql1,mysql2 mysql2_jdbcUrl = jdbc:mysql://127.0.0.1:3306/test2?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull mysql2_user = root mysql2_password =root
手动或者java读写第二个数据源执行该方法
public void resourceData() {
List<ActiveRecordPlugin> list = new ArrayList<ActiveRecordPlugin>();
Prop pp = PropKit.use("dataSource.txt");
String[] configName = pp.get("configName").split(",");
for (String item : configName) {
System.out.println("---------:" + item);
DruidPlugin druidPlugin = new DruidPlugin(pp.get(item + "_jdbcUrl"), pp.get(item + "_user"), pp.get(item + "_password").trim());
ActiveRecordPlugin arp = new ActiveRecordPlugin(item, druidPlugin);
arp.addMapping("aut_user", HelloWorldDao.class);
Ret.create("druidPlugin", druidPlugin).set("arp", arp);
list.add(arp);
}
for (ActiveRecordPlugin rs : list) {
rs.start();
}
}这个方法的意思是不重启Tomcat重新去加载一次txt配置数据源的文本,但是我在重新加载的时候报错了,不知道什么原因。
报错代码如下:
[ERROR]-[Thread: http-apr-8080-exec-10]-[com.jfinal.core.ActionHandler.handle()]: /test/resourceData
java.lang.RuntimeException: ActiveRecord start error: ActiveRecordPlugin need DataSource or DataSourceProvider
at com.jfinal.plugin.activerecord.ActiveRecordPlugin.start(ActiveRecordPlugin.java:221)
at controller.ConfigController.resourceData(ConfigController.java:151)
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:497)
at com.jfinal.aop.Invocation.invoke(Invocation.java:73)
at com.jfinal.core.ActionHandler.handle(ActionHandler.java:82)
at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:73)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2508)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2497)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
异常中提到 ConfigController.java 的 151 行有问题,建议调试跟踪一下