JDBC Driver Deprecation and Compatibility
When initializing a MySQL connection, you may encounter a warning stating that com.mysql.jdbc.Driver is deprecated. The recommended class is now com.mysql.cj.jdbc.Driver, and manual loading is generally unnecessary due to SPI. However, if you are forced to switch versions due to environment constraints, you can downgrade the connector in your dependency management. For example, using an older version like 5.0.4 might be required if the newer driver causes AbstractMethodError exceptions like com.mysql.jdbc.Connection.isValid(I)Z. This specific error often occurs when there is a mismatch between the database connection pool configuration (e.g., DBCP2) and the JDBC driver version. Ensure the data source and connection pool settings are compatible with the specific driver library included in your project.
SQL Syntax and Script Execution Issues
Comment Syntax Errors: SQL scripts may fail with syntax errors if comments are formatted incorrectly. For instance, using --college directly before a command can block execution. Standard SQL comments using -- must be followed by a space.
-- This is a valid comment
CREATE TABLE example (id INT);
Table Identifier Quoting: When inserting data, using single quotes around table names (e.g., 'T_PERMISSION') triggers a syntax error. Table names should be unquoted or use backticks.
INSERT INTO T_PERMISSION VALUES (2, 'perm1', 'a', 'permission1');
Statement Ordering: SQL queries require correct clause ordering. Placing LIMIT before ORDER BY causes an error. Always sort before limiting the result set.
SELECT * FROM FtpPublicFile ORDER BY date_created DESC LIMIT #{page}, 10;
Character Encoding and File Handling
Illegal UTF-8 Characters: Build errors like "illegal character: '\ufeff'" indicate the presence of a BOM (Byte Order Mark). This can be resolved by converting the file encoding from "UTF-8" to "UTF-8 without BOM" using a text editor like Notepad++.
Gradle Compilation Encoding: If Gradle builds fail with "unmappable character for encoding GBK", you must explicitly set the compilation encoding to UTF-8 in the build.gradle file.
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
Resource Access in JARs: After packaging an application into a JAR, accessing resources via filesystem paths (e.g., getFile()) will fail because the contents are no longer standard files on the disk. You must use InputStream to read them.
ClassPathResource resource = new ClassPathResource("static/img/" + filename);
try (InputStream inputStream = resource.getInputStream()) {
// Process stream
}
Framework Configuration Errors
Spring Boot Mapper Scanning: MyBatis mappers (interfaces) are not detected by standard @ComponentScan. You must use @MapperScan to specify the base package containing your mapper interfaces. Conversely, @ComponentScan is suitable for repositories or standard service components.
Circular View Path: A "Circular view path" error in Spring Boot typically occurs when a request mapping returns a String that matches the URL path itself, causing an infinite loop. Rename the view return value or the endpoint path to resolve this conflict.
JAX-RS MessageBodyWriter: Errors indicating "No message body writer has been found for class..." often happen when returning complex objects like Lists or custom POJOs in XML/JSON formats. Ensure your POJOs are annotated with @XmlRootElement (for XML) and include a no-argument constructor. Additionally, verify that your service methods use @Produces instead of @Consumes to define the response content type.
File Upload Errors: Current request is not a multipart request implies the client is not sending data correctly. The request body must use form-data, with the file key set to "File".
Build and Deployment Issues
Java Version Mismatch: The error Unsupported major.minor version 52.0 means the code was compiled with Java 8 but is running on a lower JRE (e.g., Java 7). Ensure the deployment environment uses JDK 8 or higher. Conversely, if you see "lambda expressions not supported", set the Maven or Gradle source compatibility to 1.8 or higher.
Gradle Property Errors: If Gradle fails to recognize mainClassName, apply the application plugin in your build script.
apply plugin: 'application'
mainClassName = 'com.example.MainApplication'
Maven Wrapper Corruption: Gradle build failures such as "error in opening zip file" usually indicate a corrupted Gradle distribution zip in the wrapper cache. Delete the corrupted file from ~/.gradle/wrapper/dists/ and let the build download it again, or manually place the correct zip in that directory.
Runtime and Server Configuration
Tomcat Shutdown Failures: If Tomcat fails to shutdown with a "Connection refused" error on port 8005, it is often due to a corrupted web application (WAR) deployed in the container. Removing the faulty WAR allows the server to stop correctly.
WEB-INF Access: Resources inside WEB-INF are protected and cannot be accessed directly via a browser URL. To serve these files, you must configure a mapping in web.xml or use a Spring Controller to forward the request.
Ehcache Hostname Resolution: Ehcache might throw an UnknownHostException if it cannot resolve the local hostname. To fix this, edit the /etc/hosts file and map your hostname to 127.0.0.1.