Common Java Backend Pitfalls and Practical Solutions
The article shares a Java backend developer’s recent challenges—including duplicated configuration files, hard‑coded parameters, mixed logging practices, unchecked Maven dependencies, and production database inconsistencies—and offers practical solutions such as consolidating Spring configuration, standardizing logging, enforcing code reviews, and proper Maven pom handling.
Hello everyone, I am your friend "Architecture Jun", a architect who can write code and poetry.
On my first day at a new job I was immediately assigned tasks, set up a new computer, and started working right away.
Opening code reveals many problems
1. The application reads two configuration files: one internal (WEB-INF) and one external, causing confusion about which settings take precedence. The external file overrides the internal one, but inconsistent handling of property prefixes makes the configuration messy. prop_c.setProperty(key, value); The code also uses a synchronized put method that throws a NullPointerException if the value is null, and the underlying collection is a hashTable.
public synchronized V put(K key, V value) {
// Make sure the value is not null
if (value == null) {
throw new NullPointerException();
}
}2. Many parameters are hard‑coded in the source, e.g., role checks like role.haveRole("ADMIN_USE"), making future changes labor‑intensive.
3. Logging is a mix of System.out.println and proper logger calls, and stack traces are often omitted, which hampers troubleshooting.
4. Lack of technical manager review leads to production packages being released by a single developer, causing code and database inconsistencies between environments.
5. Arbitrary changes to the production database rely solely on developers' professionalism, increasing risk.
6. Maven dependency issues arise when a pom file depends on another pom without providing a generated JAR. Adding <type>pom</type> under dependency can resolve this, though the purpose is unclear.
Solutions
For new or upgraded projects, use Spring's application.xml/yml for configuration. In production, pass the configuration file location via command line, e.g.:
nohup java -Dfile.encoding=UTF-8 -Dspring.config.location=server/src/main/config/application.properties -jar xxx.jar &Adopt consistent coding standards, use proper logging (prefer logger with stack traces), avoid hard‑coding values, enforce code reviews, and keep production and development environments synchronized. When possible, avoid modifying source code of existing projects; instead, add extensions.
These practices help reduce the recurring issues described above.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Architect Essentials
Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
