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")