mybatis练习逆向工程时,除了好几次,解决不了,求大神帮忙!!!!!!

weixin_44348990 2019-07-20 10:47:07
log4j:WARN Fatal parsing error 54 and column 16
log4j:WARN XML 文档结构必须从头至尾包含在同一个实体内。
log4j:ERROR Could not parse url [file:/C:/Users/Administrator/eclipse-workspace/Study/target/classes/log4j.xml].
org.xml.sax.SAXParseException; systemId: file:/C:/Users/Administrator/eclipse-workspace/Study/target/classes/log4j.xml; lineNumber: 54; columnNumber: 16; XML 文档结构必须从头至尾包含在同一个实体内。
at java.xml/com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at java.xml/com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at org.apache.log4j.xml.DOMConfigurator$2.parse(DOMConfigurator.java:769)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:871)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:778)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:526)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:127)
at org.apache.log4j.Logger.getLogger(Logger.java:117)
at org.mybatis.generator.logging.Log4jImpl.<init>(Log4jImpl.java:30)
at org.mybatis.generator.logging.LogFactory$Log4jLoggingLogFactory.getLog(LogFactory.java:70)
at org.mybatis.generator.logging.LogFactory.getLog(LogFactory.java:43)
at org.mybatis.generator.internal.db.DatabaseIntrospector.<init>(DatabaseIntrospector.java:98)
at org.mybatis.generator.config.Context.introspectTables(Context.java:634)
at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:257)
at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:139)
at com.neuedu.test.MybatisGenTest.generator(MybatisGenTest.java:29)
at com.neuedu.test.MybatisGenTest.main(MybatisGenTest.java:52)
log4j:WARN No appenders could be found for logger (org.mybatis.generator.internal.db.DatabaseIntrospector).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.


代码如下:

package com.neuedu.test;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

public class MybatisGenTest {
public void generator() {
List<String> waList = new ArrayList<String>();
boolean overwrite = true;
// 指定配置文件
File configFile = new File("C:\\Users\\Administrator\\eclipse-workspace\\Study\\src\\main\\resources\\config.xml");
ConfigurationParser configurationParser = new ConfigurationParser(waList);
Configuration configuration = null;
MyBatisGenerator myBatisGenerator = null;
try {
configuration = configurationParser.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
myBatisGenerator = new MyBatisGenerator(configuration, callback, waList);
myBatisGenerator.generate(null);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XMLParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
//执行main方法生成代码,实体类等
public static void main(String[] args) {

MybatisGenTest mybatisGenTest = new MybatisGenTest();
mybatisGenTest.generator();

}
}



配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!-- 数据库驱动包位置 -->
<classPathEntry
location="C:/Users/Administrator/eclipse-workspace/Study/src/main/resources/mysql-connector-java-8.0.15.jar"/>
<context id="sqlGenerate" targetRuntime="MyBatis3">
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>

<!-- 数据库链接URL、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/java4?serverTimezone=GMT%2B8"
userId="root" password="">
</jdbcConnection>

<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer; 为 true时把JDBC DECIMAL和NUMERIC类型解析为java.math.BigDecimal -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>

<!-- 生成Pojo包名和位置 -->
<javaModelGenerator
targetPackage="com.neuedu.pojo"
targetProject="/Study/src/main/java">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="true" />
<!-- 清理前后的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>

<!-- 生成Mapper映射XML文件位置 -->
<sqlMapGenerator
targetPackage="com.neuedu.mapper"
targetProject="/Study/src/main/java">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>

<!-- 生成Mapper接口文件位置 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.neuedu.mapper"
targetProject="/Study/src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>

<!-- 要生成哪些表(更改tableName和domainObjectName就可以) -->
<!-- tableName:要生成的表名
domainObjectName:生成后的实例名
enableCountByExample:Count语句中加入where条件查询,默认为true开启
enableUpdateByExample:Update语句中加入where条件查询,默认为true开启
enableDeleteByExample:Delete语句中加入where条件查询,默认为true开启
enableSelectByExample:Select多条语句中加入where条件查询,默认为true开启
selectByExampleQueryId: Select单个对象语句中加入where条件查询,默认为true开启 -->
<table tableName="t_admin" domainObjectName="Admin"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false"></table>
<table tableName="t_user" domainObjectName="User"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false"></table>
<table tableName="t_category" domainObjectName="Category"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false"/>
<table tableName="t_salesorder" domainObjectName="Salesorder"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false"/>
<table tableName="t_product" domainObjectName="Product"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false"/>
<table tableName="t_salesitem" domainObjectName="Salesitem"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false"/>
</context>
</generatorConfiguration>
...全文
367 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_44348990 2019-07-20
  • 打赏
  • 举报
回复
已解决,问题在log4j.xml配置文件结尾少了 </log4j:configuration>
新问题:
og4j: reset attribute= "false".
log4j: Threshold ="null".
log4j:WARN No appenders could be found for logger (org.mybatis.generator.internal.db.DatabaseIntrospector).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

58,451

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧