最近在搭建框架時遇到不少細節問題,時間久了就很容易忘記,在此記錄一下。html
1.問題:Warning:java: 來自注釋處理程序 'org.antlr.v4.runtime.misc.NullUsageProcessor' 的受支持 source 版本 'RELEASE_6' 低於 -source '1.8'java
解決辦法:這個問題是依賴包版本致使,更新依賴包便可。mysql
<dependency> <groupId>org.antlr</groupId> <artifactId>antlr4</artifactId> <version>4.7.2</version> </dependency>
2.問題:Warning:java: 未知的枚舉常量 javax.annotation.meta.When.MAYBEgit
解決辦法:緣由是找不到默認的 javax.annotation.meta.When的類文件,缺乏對應第三方依賴包,添加對應依賴包便可。web
<dependency> <groupId>com.google.code.findbugs</groupId> <artifactId>annotations</artifactId> <version>3.0.1</version> </dependency>
3.問題:在構建springboot的時候,內部報了一個錯誤信息,可是不影響正常使用。spring
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數據時出現的錯誤。sql
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包時報沒有主清單屬性錯誤。api
解決辦法:查看jar包內部META-INF目錄下的MANIFEST.MF文件裏面是否包含Main-Class 配置。若是沒有則設置打包配置。springboot
<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將只掃描註解配置的包而再也不自動掃描啓動類所在包及子包下的文件。
6.問題:打包項目,報Liquibase缺乏配置文件 db/changelog/db.changelog-master.yaml。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration$LiquibaseConfiguration': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Cannot find changelog location: class path resource [db/changelog/db.changelog-master.yaml] (please add changelog or check your Liquibase configuration) at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:139) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE] Caused by: java.lang.IllegalStateException: Cannot find changelog location: class path resource [db/changelog/db.changelog-master.yaml] (please add changelog or check your Liquibase configuration) at org.springframework.util.Assert.state(Assert.java:94) ~[spring-core-5.0.11.RELEASE.jar:5.0.11.RELEASE] at org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration$LiquibaseConfiguration.checkChangelogExists(LiquibaseAutoConfiguration.java:113) ~[spring-boot-autoconfigure-2.0.7.RELEASE.jar:2.0.7.RELEASE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:366) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:309) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE] ... 29 common frames omitted
解決辦法:1、能夠設置不須要liquibase,spring.liquibase.enabled=false 。 2、在資源文件中添加對應的配置文件信息,配置文件參考 http://www.liquibase.org/documentation/yaml_format.html 。
Liquibase簡介
Liquibase是一個數據庫表結構迭代演進變動的管理工具。開發人員能夠不是直接針對某個特定的數據庫編寫SQL的建立、更新或刪除數據庫對象,而是在經過XML、YAML、JSON等文件中定義描述他們所需的數據庫表結構的變動。這些變動能夠包含tables、views、columns、indexes、foreignkeys、primarykeys、uniqueconstraints、data等。
Liquibase特性
Liquibase Maven依賴:
<dependency> <groupId>org.liquibase</groupId> <artifactId>liquibase-core</artifactId> </dependency>