spring boot mybatis 简单报错

engourdi 2019-04-12 06:10:18
@SpringBootApplication//(exclude = DataSourceAutoConfiguration.class)
@MapperScan("com.ex.mybatis.generator.mapper")

public class GeneratorApplication implements ApplicationRunner{
@Autowired
UserMapper userMapper;

public static void main(String[] args) {
SpringApplication.run(GeneratorApplication.class, args);
}
@Override
public void run(ApplicationArguments args) throws Exception {
//generateArtifacts();

User user = new User().withName("123").withCity("abc").withType(13);
userMapper.insert(user);
log.info(user.toString());
UserExample ue = new UserExample();
ue.createCriteria().andCityEqualTo("xxx");
List<User> list = userMapper.selectByExample(ue);
list.forEach(c->log.info(c.toString()));

UserExample ue1 = new UserExample();
ue1.createCriteria().andTypeGreaterThan(80);
list = userMapper.selectByExample(ue1);
list.forEach(c->log.info(c.toString()));
}

注释掉DataSourceAutoConfiguration 报
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).


不注释 (exclude = DataSourceAutoConfiguration.class) 报
Action:

Consider defining a bean of type 'com.ex.mybatis.generator.mapper.UserMapper' in your configuration.

配置为:
<properties resource="application.properties"/>
<classPathEntry location="C:\Users\ex\.m2\repository\mysql\mysql-connector-java\8.0.15\mysql-connector-java-8.0.15.jar" />
<context id="MyGeneratorTables" targetRuntime="MyBatis3">
<plugin type="org.mybatis.generator.plugins.FluentBuilderMethodsPlugin" />
<plugin type="org.mybatis.generator.plugins.ToStringPlugin" />
<plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
<plugin type="org.mybatis.generator.plugins.RowBoundsPlugin" />

<jdbcConnection driverClass="${driverClassName}"
connectionURL="${url}"
userId="${username}"
password="${password}">
</jdbcConnection>

<javaModelGenerator targetPackage="com.ex.mybatis.generator.model"
targetProject="./src/main/java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>

<sqlMapGenerator targetPackage="com.ex.mybatis.generator.mapper"
targetProject="./src/main/resources/mapper">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<javaClientGenerator type="MIXEDMAPPER"
targetPackage="com.ex.mybatis.generator.mapper"
targetProject="./src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<table tableName="hj_user" domainObjectName="User" >
<generatedKey column="id" sqlStatement="CALL IDENTITY()" identity="true" />
</table>
</context>

mybatis.mapper-locations=classpath*:/mapper/**/*.xml
mybatis.type-aliases-package=com.ex.mybatis.generator.model
mybatis.type-handlers-package=com.ex.mybatis.generator.handler
mybatis.configuration.map-underscore-to-camel-case=true
driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/hj?useunicode=true&characterEncoding=utf8&serverTimezone=UTC
username=root
password=ex


springboot 2.1.4 mybatis-spring-boot-starter2.0.1
...全文
69 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
engourdi 2019-04-12
  • 打赏
  • 举报
回复
解决了 忘了 自己吧spring.datasource的配置删掉了 还有+了@EnableConfigurationProperties 注解

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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