Skip to main content

Java Problems Summary

Solving Maven Remote Repository Jar Download Failures

Go to Maven Repository to find the corresponding dependency and download it.

Go to the download directory and execute the following command, replacing -DgroupId, -DartifactId, -Dversion, -Dfile

mvn install:install-file -DgroupId=io.confluent -DartifactId=kafka-schema-registry-client -Dversion=4.1.0 -Dpackaging=jar  -Dfile=kafka-schema-registry-client-4.1.0.jar

mvnw clean occurs Some Enforcer rules have failed

Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce
(enforce-versions) on project SIMI: Some Enforcer rules have failed. Look above for
specific messages explaining why the rule failed. -> [Help 1]

not solved! stackoverflow website

To skip enforcer (not always working)

mvn clean install -Denforcer.skip=true

To continue the build if error

mvn clean install -Denforcer.fail=false
./mvnw clean install -DskipDistribution=true  -Denforcer.skip=true

UncategorizedSQLException when SQL query null value is mapped to int type

Change BO property from int to Integer type

org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; 
uncategorized SQLException for SQL []; SQL state [null]; error code [0];

Mysql tinyint is toxic

mysql do not use field type tinyint, possibly your update of 1 will become 49

See blog

MybatisPlus Invalid bound statement (not found) exception

See article


idea terminal Chinese garbled characters

Reference article

# solve idea terminal Chinese garbled
export LANG="zh_CN.UTF-8"
export LC_ALL="zh_CN.UTF-8"

Other Problems

Dynamic Data Source Problems

If the operation used has a transaction, you need to set the data source before the Dao layer. In Dao or Mybatis-plus, service with dao will switch data source invalidly.

jackson serialization problems

LocalDateTime not supported by default

Java 8 date/time type java.time.LocalDateTime not supported by default:
add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable
handling (through reference chain: java.util.ArrayList[0]->xxx.xxx.xxx.xxx.XxxxPo["updatetime"])

First troubleshoot where it is reported

  1. If Spring Boot can be extended: directly extend ObjectMapper
@Configuration
public class JacksonConfig implements WebMvcConfigurer {
@Override
public void extendMessageConverters(final List<HttpMessageConverter<?>> converters) {
MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
objectMapper.registerModule(new JavaTimeModule());
messageConverter.setObjectMapper(objectMapper);
converters.add(0, messageConverter);
}
}
  1. If cannot extend, consider skipping Bean serialization step, such as using method to convert Bean to Map
  2. If really no way, use Fastjson or Gjson instead

Second field uppercase problem

  1. Use @JsonProperty

@JsonProperty is used to explicitly tell Jackson:

"This field (or method, constructor parameter) is to be used as a JSON property, and the property name is XXX."

  1. Use @JsonAutoDetect
@JsonAutoDetect(
fieldVisibility = JsonAutoDetect.Visibility.ANY,
getterVisibility = JsonAutoDetect.Visibility.NONE,
setterVisibility = JsonAutoDetect.Visibility.NONE)

Members used in serialization and deserialization

Usage LocationInfluence DirectionCommon Usage
FieldSerialization + DeserializationForce include private fields
getterSerializationChange output field name
setterDeserializationChange input field name
Constructor ParameterDeserializationMap JSON parameter name to constructor parameter
record ParameterSerialization + DeserializationControl JSON property name

Database Connection Pool Configuration Problems

When using Druid connection pool, config parameter validationInterval must be less than timeBetweenEvictionRunMillis, ensuring database connection is always available.

API Interface Standards

  • Query data volume
  • Input parameter check
  • Response message large integer, floating point fields use string type
  • Input parameter type not primitive type
Agreement
The code part of this work is licensed under Apache License 2.0 . You may freely modify and redistribute the code, and use it for commercial purposes, provided that you comply with the license. However, you are required to:
  • Attribution: Retain the original author's signature and code source information in the original and derivative code.
  • Preserve License: Retain the Apache 2.0 license file in the original and derivative code.
The documentation part of this work is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License . You may freely share, including copying and distributing this work in any medium or format, and freely adapt, remix, transform, and build upon the material. However, you are required to:
  • Attribution: Give appropriate credit, provide a link to the license, and indicate if changes were made.
  • NonCommercial: You may not use the material for commercial purposes. For commercial use, please contact the author.
  • ShareAlike: If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.