-
Notifications
You must be signed in to change notification settings - Fork 0
Complete Spring Boot Migration for faces-example2 #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.struts.webapp.example2.controller; | ||
|
|
||
| import jakarta.servlet.http.HttpSession; | ||
|
|
||
| import org.apache.struts.webapp.example2.Constants; | ||
| import org.apache.struts.webapp.example2.User; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.ui.Model; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
|
|
||
| @Controller | ||
| public class WelcomeController { | ||
|
|
||
| @GetMapping({"/", "/welcome"}) | ||
| public String welcome(HttpSession session, Model model) { | ||
| User user = (User) session.getAttribute(Constants.USER_KEY); | ||
| if (user != null) { | ||
| model.addAttribute("user", user); | ||
| } | ||
| return "welcome"; | ||
| } | ||
|
|
||
| @GetMapping("/mainMenu") | ||
| public String mainMenu(HttpSession session, Model model) { | ||
| User user = (User) session.getAttribute(Constants.USER_KEY); | ||
| if (user == null) { | ||
| return "redirect:/editLogon"; | ||
| } | ||
| model.addAttribute("user", user); | ||
| return "mainMenu"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,11 @@ spring.thymeleaf.suffix=.html | |
| # Message source configuration | ||
| spring.messages.basename=messages | ||
| spring.messages.encoding=UTF-8 | ||
|
|
||
| # Database configuration | ||
| # Uses the existing database.xml from webapp/WEB-INF for sample data | ||
| app.database.path=classpath:database.xml | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Default The Root Cause and ImpactBecause the resource doesn't exist on the classpath, The comment in Impact: The first two branches (lines 67-77) of the Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| # Logging | ||
| logging.level.org.apache.struts.webapp.example2=DEBUG | ||
| logging.level.org.springframework.web=INFO | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Database
close()/save()called twice on shutdown due to@PreDestroyplus Spring's inferred destroy methodThe
@PreDestroy cleanup()method atDatabaseConfiguration.java:164explicitly callsdatabase.close(). However, Spring's@Beanannotation defaults todestroyMethod = "(inferred)", which auto-detects and invokes public no-argclose()orshutdown()methods on returned beans. SinceUserDatabasedeclarespublic void close() throws Exception(UserDatabase.java:61), Spring will also automatically callclose()on theuserDatabasebean during shutdown.Detailed Explanation
This results in
MemoryUserDatabase.close()being called twice during application shutdown:close()on theuserDatabasebean@PreDestroy cleanup()onDatabaseConfigurationcallsdatabase.close()on the same instanceEach
close()invocation triggerssave()(MemoryUserDatabase.java:106-110), which performs a full file-write-and-rename dance to disk. While the secondsave()doesn't crash (it's effectively idempotent), it performs unnecessary file I/O during shutdown.Fix: Either remove the
@PreDestroy cleanup()method entirely (relying on Spring's inferred destroy), or annotate the@Beanwith an explicitdestroyMethodto prevent double invocation, e.g.@Bean(destroyMethod = "close")and removecleanup(), or@Bean(destroyMethod = "")to disable inference and keepcleanup().Was this helpful? React with 👍 or 👎 to provide feedback.