springboot中遇到的一些问题

1.Spring Framework maven依赖
      

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring</artifactId>
            <version>2.5.6.SEC03</version>
        </dependency>

2. 启动报错: Failed to configure a DataSource: 'url' attribute is not specified and no embedded

原因是没有配置数据连接,解决此错误,目前有两种办法:

 (1)在启动类中

@SpringBootApplication(exclude = {MongoAutoConfiguration.class,DataSourceAutoConfiguration.class})

因为springboot启动的时候就会扫描所有的信息,但是可以通过exclude将不需要类排除掉

 (2)建立数据库连接

#
server.port=@server.port@
server.servlet.context-path=/**
#db配置
spring.datasource.url=@jdbc.url@
spring.datasource.username=@jdbc.username@
spring.datasource.password=@jdbc.password@
spring.datasource.driver-class-name=@jdbc.driver@
spring.datasource.max-idle=10
spring.datasource.max-wait=10000
spring.datasource.min-idle=5
spring.datasource.initial-size=5
spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
#文件上传大小限制
spring.servlet.multipart.maxFileSize=-1
spring.servlet.multipart.maxRequestSize=-1
#日志基本信息配置
logging.level.root=WARN
#logging.level.org.springframework.web=DEBUG
logging.file=log/my.log
logging.pattern.console=%d{yyyy/MM/dd-HH:mm:ss} [%thread] %-5level %logger- %msg%n
logging.pattern.file=%d{yyyy/MM/dd-HH:mm} [%thread] %-5level %logger- %msg%n
#Redis
redis.host=@redis.host@
redis.port=@redis.port@
redis.database=1
#设置spring-boot 编码格式
banner.charset=UTF-8
server.tomcat.uri-encoding=UTF-8
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
spring.messages.encoding=UTF-8

3.启动报错 Consider defining a bean of type ‘XXX’ in your configuration.

Description:

Field userEntityMapper in com.xxx.xxx.service.UserService required a bean of type 'com.xxx.xxx.dao.UserMapper' that could not be found.

Action:

Consider defining a bean of type 'com.xxx.xxx.dao.UserMapper' in your configuration.

解决方法:

(1) 在springboot的配置文件添加,mybatis的配置如下所示:

mybatis:
  typeAliasesPackage: com.xxx.xxx.dao.entity
  mapperLocations: classpath:mapper/*.xml

(2)在service类中添加注解@Service

         在mapper中添加注解@Mapper

(3)在启动类上加上@MapperScan注解,手动指定application类要扫描哪些包下的注解,如下所示:

@MapperScan("com.*.*.modules.dao")

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值