Showing Posts From

Java

SpringBoot Transaction Not Rolling Back Summary

Cause The database engine must not be MyISAM Solution Use InnoDB engine, because MyISAM does not support transactions.

ConfigurationProperties Static Variable Injection Pitfalls

Problem Description When using @ConfigurationProperties annotation, static variables cannot be injected directly. Solution private static String copyrightYear;public static String getCopyrightYear() { return copyrightYear; }// set method cannot have static keyword public void setCopyrightYear(String copyrightYear) { HaiAnConfig.copyrightYear = copyrightYear; }/* // This won't work for injection public static void setCopyrightYear(String copyrightYear) { HaiAnConfig.copyrightYear = copyrightYear; } */Key Point The set method cannot have the static keyword, otherwise @ConfigurationProperties cannot inject values correctly.

Spring Multi-Module Development Pitfalls

Problem Description Running module: sou-main Created module: sou-admin sou-main must depend on sou-admin, otherwise the running module cannot find classes from the newly created module Solution Add dependency in sou-main: <!-- sou-main--> <dependency> <groupId>com.sou</groupId> <artifactId>sou-admin</artifactId> </dependency>Configure version management in sou-parent: <!-- sou-parent--> <dependencyManagement> <dependency> <groupId>com.sou</groupId> <artifactId>sou-admin</artifactId> <version>1.0</version> </dependency> </dependencyManagement>

SpringBoot Static Resources Not Accessible After Packaging

Problem Description After packaging SpringBoot into a jar file, static resources become inaccessible. Solution Add resource configuration in pom.xml: <build> <resources> <resource> <!-- Copy jsp files to META-INF directory when packaging--> <!-- Specify which directory's resource files the resources plugin should handle --> <directory>src/main/resources</directory> <!--Must be placed here to be accessible--> <targetPath>META-INF/resources</targetPath> <includes> <include>**/**</include> </includes> </resource> </resources> </build>