记录spring boot使用中遇到的问题
2018-01-30 16:11
387 查看
问题1,mapper的方法找不到:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.baozun.roms.admin.mapper.ShopAdminMapper.list
这个问题是因为mybatis的数据库配置 ,没有加载到mapper文件,导致的,需要在application.yml中配置对应的数据库配置和数据库指向配置就可以了,很奇怪的是,在application.properties文件中配置无效。
application.yml配置:
关于spring.datasourse.type的设置,不设置就是默认数据源,如果设置druid数据源,引入jar包时会报错
所有我注释了,使用的是默认的数据源。测试可以使用。
问题2:APPLICATION FAILED TO START
问题明细:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'actionGradeAdminController':
Unsatisfied dependency expressed through field 'actionGradeAdminService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'actionGradeAdminServiceImpl': Unsatisfied dependency expressed through
field 'actionGradeAdminMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.baozun.roms.admin.mapper.ActionGradeAdminMapper' available: expected at least 1 bean which qualifies as autowire
candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
***************************
APPLICATION FAILED TO START
***************************
问题原因:mapper.java文件引入的注解错误,导致匹配不到,我这边引入的是@Repository,是错误的。
解决方案:把@Repository改为@Mapper,引入的是
问题3:页面访问跨域问题:
解决方法,引用WebMvcConfigurerAdapter类,重写addCorsMappings方法。实例:
}}
未完待续!
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.baozun.roms.admin.mapper.ShopAdminMapper.list
这个问题是因为mybatis的数据库配置 ,没有加载到mapper文件,导致的,需要在application.yml中配置对应的数据库配置和数据库指向配置就可以了,很奇怪的是,在application.properties文件中配置无效。
application.yml配置:
spring: datasource: name: test url: "数据库链接" username: 数据库名 password: "密码" # 使用druid数据源,也可以使用默认的,如果使用druid引入的包会报错。 # type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver filters: stat maxActive: 10 initialSize: 1 maxWait: 60000 minIdle: 1 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: select 'x' testWhileIdle: true testOnBorrow: false testOnReturn: false poolPreparedStatements: true maxOpenPreparedStatements: 20 mybatis: mapperLocations: classpath:sqlmap/*.xml //指向mapper.xml文件地址 typeAliasesPackage: com.baozun.roms.admin.entity
关于spring.datasourse.type的设置,不设置就是默认数据源,如果设置druid数据源,引入jar包时会报错
<dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.2</version> </dependency>
所有我注释了,使用的是默认的数据源。测试可以使用。
问题2:APPLICATION FAILED TO START
问题明细:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'actionGradeAdminController':
Unsatisfied dependency expressed through field 'actionGradeAdminService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'actionGradeAdminServiceImpl': Unsatisfied dependency expressed through
field 'actionGradeAdminMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.baozun.roms.admin.mapper.ActionGradeAdminMapper' available: expected at least 1 bean which qualifies as autowire
candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
***************************
APPLICATION FAILED TO START
***************************
问题原因:mapper.java文件引入的注解错误,导致匹配不到,我这边引入的是@Repository,是错误的。
解决方案:把@Repository改为@Mapper,引入的是
import org.apache.ibatis.annotations.Mapper;
问题3:页面访问跨域问题:
解决方法,引用WebMvcConfigurerAdapter类,重写addCorsMappings方法。实例:
import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; /** * @Author: * @Time: Created In 14:12 2018/1/30 * @Author: */ @Configuration public class MyWebAppConfigurer extends WebMvcConfigurerAdapter { @Override public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**") //设置访问的路径,斜杠加星星,表示无限制 .allowedMethods("GET", "POST"); //设置访问的方式
}}
未完待续!
相关文章推荐
- 记录问题:springboot中使用Mybatis-pagehelper分页插件遇到的版本兼容问题
- 关于SpringBoot2.0版本使用过程中遇到问题
- 【springboot】使用注解遇到的问题
- 使用gradle来构建Spring boot时遇到的问题
- SpringBoot使用可能遇到的问题及解决方法
- 使用springboot时,@Scheduled定时器遇到的问题
- 在idea里使用SpringBoot整合MyBatis时遇到的Mapper扫描不到的问题
- 使用Spring Boot搭建个人博客遇到的问题
- Spring Boot使用RestTemplate消费REST服务的几个问题记录
- Idea使用Maven创建多模块SpringBoot项目问题记录
- spring boot 1.5.4使用JPA,遇到Mysql区分大小写的问题
- springboot的restController使用swagger遇到的问题。
- springboot使用遇到的问题
- 关于使用springboot中遇到的些问题
- spring boot 项目增加flyway的使用遇到问题解决
- 学习使用solr时遇到的一些问题,记录
- Qt 笔记(记录使用Qt中遇到的一些问题)
- 使用Spring-Jms监听ActiveMQ时遇到的问题
- 使用ant对项目进行多渠道打包时遇到问题记录
- 使用FastDFS遇到问题记录(转)