Springboot 注意事项 慢慢累积

xiaoxiao2021-03-01  46

1、spring boot maven Unable to find main class 在pom中加入 二者选其一  

<properties> <start-class>com.EurekaApplication</start-class>main方法类路径 </properties> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.EurekaApplication</mainClass>main方法类路径 </configuration> </plugin> </plugins> </build>

 

2、看提示信息显示在chinesedrug类中没有test这个属性,才发现原来springboot还有这种属性检查。

将实现的接口repository注释掉后,错误提示消失。

3、springboot项目启动时,如果没有数据库配置,启动时会抛出如下异常。

Description: Cannot determine embedded database driver class for database type NONE Action: 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).

在maven中你导入了数据库配置并且在appliaction.yml/appliaction.properties中配置数据库相关信息。。例如:

<dependency>     <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> spring: datasource: username: root password: 123 url: jdbc:mysql://192.168.1.6:3306/engine driver-class-name: com.mysql.jdbc.Driver

或者排除自动配置 @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})。

4.当使用这种方式配置数据源,url名称使用的是jdbc-url     jdbc-url: jdbc:mysql://192.168.1.4:3306/mysql     public DataSource testDataSource() {         return DataSourceBuilder.create().build();     }5.使用这种方式配置数据源,url名称使用的是url     url: jdbc:mysql://192.168.1.4:3306/mysql​​​​​​​     @ConfigurationProperties(prefix = "local.datasource")     public DataSourceProperties localDataSourceProperties() {         return new DataSourceProperties();     }     @Bean(name = "localDateSource")     @ConfigurationProperties(prefix = "local.datasource")     public DataSource firstDataSource() {         return localDataSourceProperties().initializeDataSourceBuilder().build();     }6.在使用springboot时使用freemarker作为模板时,默认情况下输出的数字是千分位格式化的如:0,000,000。导致使用一些js框架时读取数字失败。 可以在使用number_format: 0.##  设置格式。

 

转载请注明原文地址: https://www.6miu.com/read-3450232.html

最新回复(0)