首页 > 学院 > 开发设计 > 正文

Spring Boot 菜鸟教程 异常 集锦

2019-11-10 20:04:36
字体:
来源:转载
供稿:网友

异常1.集成SPRing Data JPA

异常信息摘要:

org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).

异常信息说明:不知道使用什么数据库,需要在pom.xml标注使用什么数据库,如h2 解决思路:修改pom.xml

<dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope></dependency>

异常2.集成MyBatis没有标注@Mapper注解

异常信息摘要:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.jege.spring.boot.mybatis.UserMapperTest': Unsatisfied dependency expressed through field 'userMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean found for dependency [com.jege.spring.boot.mybatis.mapper.UserMapper]: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

异常信息说明:说mapper接口不能成功注入 解决思路:使用spring boot后没有去指定扫描那个包,所以必须标注@org.apache.ibatis.annotations.Mapper在接口类上面或者启动类标注@MapperScan(“com.jege.spring.boot.mybatis.mapper”)


异常3.启动类必须放入包里面

异常信息摘要:

** WARNING ** : Your applicationContext is unlikely to start due to a @ComponentScan of the default package.

异常信息说明:应用程序不能从根目录的包开始 Application.java 文件不能直接放在main/java文件夹下,必须要建一个包把他放进去


异常4.上传文件太大了

异常信息摘要:

org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field upfile exceeds its maximum permitted size of 1048576 bytes.

异常信息说明:默认最大上传大小为1M 解决思路:Spring Boot升级到1.4到这样配置

# MULTipART (MultipartProperties)spring.http.multipart.enabled=true # Enable support of multi-part uploads.spring.http.multipart.file-size-threshold=0 # Threshold after which files will be written to disk. Values can use the suffixed "MB" or "KB" to indicate a Megabyte or Kilobyte size.spring.http.multipart.location= # Intermediate location of uploaded files.spring.http.multipart.max-file-size=10Mb # Max file size. Values can use the suffixed "MB" or "KB" to indicate a Megabyte or Kilobyte size.spring.http.multipart.max-request-size=10Mb # Max request size. Values can use the suffixed "MB" or "KB" to indicate a Megabyte or Kilobyte size.

解决思路:Spring Boot版本1.3.x这样配置

multipart.maxFileSize=10Mb

异常5.tomcat版本问题

异常信息摘要:

java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()

异常信息说明:找不到对应的方法 在本地mvn springboot:run 运行都没有问题。由于本地JDK版本是1.8,默认版本是tomcat8;而服务器JDK版本是1.7。解决方法 指定 tomcat版本就可以了。

<properties> <tomcat.version>7.0.52</tomcat.version></properties>

如果觉得我的文章或者代码对您有帮助,可以请我喝杯咖啡。 您的支持将鼓励我继续创作!谢谢! 微信打赏 支付宝打赏


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表