Springboot构建问题集
最近在搭建框架时遇到很多细节问题,时间久了就很容易忘记,在此记录一下。
1.问题:warning:java: 来自注释处理程序 'org.antlr.v4.runtime.misc.nullusageprocessor' 的受支持 source 版本 'release_6' 低于 -source '1.8'
解决办法:这个问题是依赖包版本导致,更新依赖包即可。
<dependency> <groupid>org.antlr</groupid> <artifactid>antlr4</artifactid> <version>4.7.2</version> </dependency>
2.问题:warning:java: 未知的枚举常量 javax.annotation.meta.when.maybe
解决办法:原因是找不到默认的 javax.annotation.meta.when的类文件,缺少对应第三方依赖包,添加对应依赖包即可。
<dependency> <groupid>com.google.code.findbugs</groupid> <artifactid>annotations</artifactid> <version>3.0.1</version> </dependency>
3.问题:在构建springboot的时候,内部报了一个错误信息,但是不影响正常使用。
logback [main] info o.h.e.j.e.i.lobcreatorbuilderimpl - hhh000424: disabling contextual lob creation as createclob() method threw error : java.lang.reflect.invocationtargetexception java.lang.reflect.invocationtargetexception: null at sun.reflect.nativemethodaccessorimpl.invoke0(native method) at sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) at sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) at java.lang.reflect.method.invoke(method.java:498) at org.hibernate.engine.jdbc.env.internal.lobcreatorbuilderimpl.usecontextuallobcreation(lobcreatorbuilderimpl.java:113) at org.hibernate.engine.jdbc.env.internal.lobcreatorbuilderimpl.makelobcreatorbuilder(lobcreatorbuilderimpl.java:54) at org.hibernate.engine.jdbc.env.internal.jdbcenvironmentimpl.<init>(jdbcenvironmentimpl.java:271) at org.hibernate.engine.jdbc.env.internal.jdbcenvironmentinitiator.initiateservice(jdbcenvironmentinitiator.java:114) at org.hibernate.engine.jdbc.env.internal.jdbcenvironmentinitiator.initiateservice(jdbcenvironmentinitiator.java:35) at org.hibernate.boot.registry.internal.standardserviceregistryimpl.initiateservice(standardserviceregistryimpl.java:88) at org.hibernate.service.internal.abstractserviceregistryimpl.createservice(abstractserviceregistryimpl.java:259) at org.hibernate.service.internal.abstractserviceregistryimpl.initializeservice(abstractserviceregistryimpl.java:233) at org.hibernate.service.internal.abstractserviceregistryimpl.getservice(abstractserviceregistryimpl.java:210) at org.hibernate.engine.jdbc.internal.jdbcservicesimpl.configure(jdbcservicesimpl.java:51) at org.hibernate.boot.registry.internal.standardserviceregistryimpl.configureservice(standardserviceregistryimpl.java:94) at org.hibernate.service.internal.abstractserviceregistryimpl.initializeservice(abstractserviceregistryimpl.java:242) at org.hibernate.service.internal.abstractserviceregistryimpl.getservice(abstractserviceregistryimpl.java:210) at org.hibernate.boot.model.process.spi.metadatabuildingprocess.handletypes(metadatabuildingprocess.java:352) at org.hibernate.boot.model.process.spi.metadatabuildingprocess.complete(metadatabuildingprocess.java:111) at org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl.metadata(entitymanagerfactorybuilderimpl.java:861) at org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl.build(entitymanagerfactorybuilderimpl.java:888) at org.springframework.orm.jpa.vendor.springhibernatejpapersistenceprovider.createcontainerentitymanagerfactory(springhibernatejpapersistenceprovider.java:57) at org.springframework.orm.jpa.localcontainerentitymanagerfactorybean.createnativeentitymanagerfactory(localcontainerentitymanagerfactorybean.java:365) at org.springframework.orm.jpa.abstractentitymanagerfactorybean.buildnativeentitymanagerfactory(abstractentitymanagerfactorybean.java:390) at org.springframework.orm.jpa.abstractentitymanagerfactorybean.afterpropertiesset(abstractentitymanagerfactorybean.java:377) at org.springframework.orm.jpa.localcontainerentitymanagerfactorybean.afterpropertiesset(localcontainerentitymanagerfactorybean.java:341) at org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1753) at org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1690) at org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:573) at org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:495) at org.springframework.beans.factory.support.abstractbeanfactory.lambda$dogetbean$0(abstractbeanfactory.java:317) at org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:222) at org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:315) at org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:199) at org.springframework.context.support.abstractapplicationcontext.getbean(abstractapplicationcontext.java:1087) at org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:857) at org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:548) at org.springframework.boot.web.servlet.context.servletwebserverapplicationcontext.refresh(servletwebserverapplicationcontext.java:142) at org.springframework.boot.springapplication.refresh(springapplication.java:754) at org.springframework.boot.springapplication.refreshcontext(springapplication.java:386) at org.springframework.boot.springapplication.run(springapplication.java:307) at org.springframework.boot.springapplication.run(springapplication.java:1242) at org.springframework.boot.springapplication.run(springapplication.java:1230) at com.digitized.server.digitizedserverapplication.main(digitizedserverapplication.java:14) caused by: java.sql.sqlfeaturenotsupportedexception: 这个 org.postgresql.jdbc.pgconnection.createclob() 方法尚未被实作。 at org.postgresql.driver.notimplemented(driver.java:640) at org.postgresql.jdbc.pgconnection.createclob(pgconnection.java:1241) ... 44 common frames omitted
解决办法:添加如下配置信息,原因是数据库默认使用的解析方式不匹配,这里是连接greenplum数据时出现的错误。
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.postgresqldialect
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
4.问题:用 java -jar 运行spring boot jar包时报没有主清单属性错误。
解决办法:查看jar包内部meta-inf目录下的manifest.mf文件里面是否包含main-class 配置。如果没有则设置打包配置。
<build> <plugins> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> <configuration> <!-- 指定该main class为全局的唯一入口 --> <mainclass>com.zsm.apidoc.apidocapplication</mainclass> <layout>zip</layout> </configuration> <executions> <execution> <goals> <goal>repackage</goal><!--可以把依赖的包都打包到生成的jar包中--> </goals> </execution> </executions> </plugin> </plugins> <resources> <resource> <directory>src/main/resources</directory> <includes> <include>*.xml</include> <include>*.properties</include> </includes> <excludes> <exclude>*.log</exclude> <exclude>*.txt</exclude> </excludes> </resource> </resources> </build>
5.问题:springboot扫描不到依赖项目的类。有一个公共项目common,要扫描的类在com.zsm.common包下,现在有一个业务项目com.zsm.user,依赖了公共项目common,在user项目application启动类在包com.zsm.user下,项目启动后找不到common项目中的bean类。
解决办法:在application启动类添加注解 @componentscan(basepackages = {"com.zsm"}) 即可解决问题,或者配置扫描多个包@componentscan(basepackages= {“com.zsm.common”,”com.zsm.user”}),或者添加@springbootapplication注解,修改包路径。添加注解后,spring将只扫描注解配置的包,而不再自动扫描启动类所在包及子包下的文件。
注意:springboot 默认扫描的路径,是该工程application启动类所在包以及所有子包下的所有文件。如果不加@springbootapplication注解,spring将只扫描注解配置的包而不再自动扫描启动类所在包及子包下的文件。