2026-03-07 05:43:15 +00:00
|
|
|
<!DOCTYPE html>
|
2026-03-19 13:53:49 +08:00
|
|
|
<html lang="en">
|
2026-03-07 05:43:15 +00:00
|
|
|
<head>
|
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
2026-03-19 13:53:49 +08:00
|
|
|
<title>Spring AOP Lab</title>
|
2026-03-07 05:43:15 +00:00
|
|
|
<style>
|
2026-03-19 13:53:49 +08:00
|
|
|
:root {
|
|
|
|
|
--bg: #eef7ef;
|
|
|
|
|
--panel: rgba(255,255,255,0.95);
|
|
|
|
|
--line: #d8e7d8;
|
|
|
|
|
--text: #102033;
|
|
|
|
|
--muted: #5c7184;
|
|
|
|
|
--brand: #3f8f2c;
|
|
|
|
|
--accent: #0f67b5;
|
|
|
|
|
--shadow: 0 20px 48px rgba(16, 32, 51, 0.12);
|
|
|
|
|
}
|
|
|
|
|
* { box-sizing: border-box; }
|
|
|
|
|
body {
|
|
|
|
|
margin: 0;
|
|
|
|
|
font-family: "Aptos", "Segoe UI", "Microsoft YaHei", sans-serif;
|
|
|
|
|
color: var(--text);
|
|
|
|
|
background:
|
|
|
|
|
radial-gradient(circle at top right, rgba(63, 143, 44, 0.14), transparent 30%),
|
|
|
|
|
radial-gradient(circle at bottom left, rgba(15, 103, 181, 0.1), transparent 24%),
|
|
|
|
|
var(--bg);
|
|
|
|
|
}
|
|
|
|
|
.page { max-width: 1280px; margin: 0 auto; padding: 24px; }
|
|
|
|
|
.hero, .card {
|
|
|
|
|
background: var(--panel);
|
|
|
|
|
border: 1px solid var(--line);
|
|
|
|
|
border-radius: 28px;
|
|
|
|
|
box-shadow: var(--shadow);
|
|
|
|
|
}
|
|
|
|
|
.hero { padding: 28px; margin-bottom: 18px; }
|
|
|
|
|
.eyebrow {
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
padding: 7px 12px;
|
|
|
|
|
border-radius: 999px;
|
|
|
|
|
background: rgba(63, 143, 44, 0.1);
|
|
|
|
|
color: var(--brand);
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
font-weight: 800;
|
|
|
|
|
letter-spacing: 0.1em;
|
|
|
|
|
text-transform: uppercase;
|
|
|
|
|
}
|
|
|
|
|
h1, h2, h3 { margin: 10px 0 12px; }
|
|
|
|
|
p { margin: 0; color: var(--muted); line-height: 1.8; }
|
|
|
|
|
.actions, .toolbar, .flow, .chips {
|
|
|
|
|
display: flex;
|
|
|
|
|
gap: 10px;
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
}
|
|
|
|
|
.btn, .btn-soft {
|
|
|
|
|
border: 0;
|
|
|
|
|
border-radius: 999px;
|
|
|
|
|
padding: 12px 18px;
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
}
|
|
|
|
|
.btn { background: linear-gradient(135deg, var(--brand), #62b049); color: #fff; }
|
|
|
|
|
.btn-soft { background: #eaf3ff; color: var(--accent); }
|
|
|
|
|
.grid {
|
|
|
|
|
display: grid;
|
|
|
|
|
gap: 18px;
|
|
|
|
|
grid-template-columns: 420px minmax(0, 1fr);
|
|
|
|
|
}
|
|
|
|
|
.card { padding: 22px; }
|
|
|
|
|
.list {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
gap: 12px;
|
|
|
|
|
margin-top: 14px;
|
|
|
|
|
}
|
|
|
|
|
.list-item, .flow-step {
|
|
|
|
|
padding: 14px;
|
|
|
|
|
border-radius: 18px;
|
|
|
|
|
border: 1px solid var(--line);
|
|
|
|
|
background: rgba(255,255,255,0.45);
|
|
|
|
|
}
|
|
|
|
|
.flow {
|
|
|
|
|
display: grid;
|
|
|
|
|
grid-template-columns: repeat(5, minmax(0, 1fr));
|
|
|
|
|
margin-top: 14px;
|
|
|
|
|
}
|
|
|
|
|
.pill {
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
padding: 6px 10px;
|
|
|
|
|
border-radius: 999px;
|
|
|
|
|
background: rgba(15, 103, 181, 0.08);
|
|
|
|
|
color: var(--accent);
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
}
|
|
|
|
|
pre {
|
|
|
|
|
margin: 0;
|
|
|
|
|
min-height: 280px;
|
|
|
|
|
padding: 16px;
|
|
|
|
|
border-radius: 18px;
|
|
|
|
|
background: #0f1621;
|
|
|
|
|
color: #deebff;
|
|
|
|
|
white-space: pre-wrap;
|
|
|
|
|
font-family: Consolas, "Courier New", monospace;
|
|
|
|
|
overflow: auto;
|
|
|
|
|
}
|
|
|
|
|
@media (max-width: 1060px) {
|
|
|
|
|
.grid, .flow { grid-template-columns: 1fr; }
|
|
|
|
|
}
|
|
|
|
|
@media (max-width: 720px) {
|
|
|
|
|
.page { padding: 14px; }
|
|
|
|
|
}
|
2026-03-07 05:43:15 +00:00
|
|
|
</style>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
2026-03-19 13:53:49 +08:00
|
|
|
<div class="page">
|
|
|
|
|
<section class="hero">
|
|
|
|
|
<div class="eyebrow">AOP Lab</div>
|
|
|
|
|
<h1>Make cross-cutting behavior visible instead of abstract.</h1>
|
|
|
|
|
<p>
|
|
|
|
|
This page focuses on the parts students usually miss: where advice wraps controller and service methods,
|
|
|
|
|
how timing is collected, and why a validation failure still counts as observed runtime behavior.
|
|
|
|
|
</p>
|
|
|
|
|
<div class="actions" style="margin-top:18px;">
|
|
|
|
|
<a class="btn-soft" href="/">Back home</a>
|
|
|
|
|
<a class="btn-soft" href="/users.html">Open user lab</a>
|
|
|
|
|
<a class="btn-soft" href="/events.html">Open event lab</a>
|
2026-03-07 05:43:15 +00:00
|
|
|
</div>
|
2026-03-19 13:53:49 +08:00
|
|
|
</section>
|
2026-03-07 05:43:15 +00:00
|
|
|
|
2026-03-19 13:53:49 +08:00
|
|
|
<div class="grid">
|
|
|
|
|
<aside class="card">
|
|
|
|
|
<div class="eyebrow">Experiment Path</div>
|
|
|
|
|
<h2>Recommended AOP sequence</h2>
|
|
|
|
|
<div class="list">
|
|
|
|
|
<div class="list-item">
|
|
|
|
|
<strong>1. Trigger controller calls</strong>
|
|
|
|
|
<p>Run the list and stats endpoints to make sure both controller and service methods execute.</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="list-item">
|
|
|
|
|
<strong>2. Trigger a validation failure</strong>
|
|
|
|
|
<p>Send an invalid user payload and compare the failed request with the successful ones.</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="list-item">
|
|
|
|
|
<strong>3. Inspect aspect output</strong>
|
|
|
|
|
<p>Load the stats endpoint and compare call counts, total time, and average time.</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-07 05:43:15 +00:00
|
|
|
|
2026-03-19 13:53:49 +08:00
|
|
|
<div class="eyebrow" style="margin-top:18px;">Advice Map</div>
|
|
|
|
|
<div class="chips" style="margin-top:12px;">
|
|
|
|
|
<span class="pill">@Before</span>
|
|
|
|
|
<span class="pill">@After</span>
|
|
|
|
|
<span class="pill">@AfterReturning</span>
|
|
|
|
|
<span class="pill">@AfterThrowing</span>
|
|
|
|
|
<span class="pill">@Around</span>
|
|
|
|
|
</div>
|
2026-03-07 05:43:15 +00:00
|
|
|
|
2026-03-19 13:53:49 +08:00
|
|
|
<div class="flow">
|
|
|
|
|
<div class="flow-step"><strong>Before</strong><p>Inspect inputs or auth context.</p></div>
|
|
|
|
|
<div class="flow-step"><strong>Around</strong><p>Start timer and continue the join point.</p></div>
|
|
|
|
|
<div class="flow-step"><strong>Controller</strong><p>Delegate work to the service.</p></div>
|
|
|
|
|
<div class="flow-step"><strong>Service</strong><p>Apply business logic.</p></div>
|
|
|
|
|
<div class="flow-step"><strong>After*</strong><p>Record result or failure details.</p></div>
|
|
|
|
|
</div>
|
|
|
|
|
</aside>
|
2026-03-07 05:43:15 +00:00
|
|
|
|
2026-03-19 13:53:49 +08:00
|
|
|
<main class="card">
|
|
|
|
|
<div class="eyebrow">Live Runs</div>
|
|
|
|
|
<h2>Run requests and inspect collected metrics</h2>
|
|
|
|
|
<p>The buttons below help you create real traffic, then inspect the aspect output without switching tools.</p>
|
2026-03-07 05:43:15 +00:00
|
|
|
|
2026-03-19 13:53:49 +08:00
|
|
|
<div class="toolbar" style="margin-top:14px;">
|
|
|
|
|
<button class="btn" type="button" onclick="loadUsers()">Load users</button>
|
|
|
|
|
<button class="btn-soft" type="button" onclick="loadUserStats()">Load user stats</button>
|
|
|
|
|
<button class="btn-soft" type="button" onclick="sendInvalidUser()">Send invalid user</button>
|
|
|
|
|
<button class="btn-soft" type="button" onclick="loadAopStats()">Load AOP stats</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="list" style="margin-top:18px;">
|
|
|
|
|
<div class="list-item">
|
|
|
|
|
<strong>What to observe in the console</strong>
|
|
|
|
|
<p>Look for controller and service timing lines. Compare success and failure paths to see how around advice still records method duration.</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="list-item">
|
|
|
|
|
<strong>What to inspect in code</strong>
|
|
|
|
|
<p>Read <code>PerformanceAspect</code> first, then compare it with the user endpoints that it wraps.</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<pre id="resultBox">Run one of the experiments above to inspect live JSON output.</pre>
|
|
|
|
|
</main>
|
2026-03-07 05:43:15 +00:00
|
|
|
</div>
|
2026-03-19 13:53:49 +08:00
|
|
|
</div>
|
2026-03-09 02:04:16 +08:00
|
|
|
|
2026-03-19 13:53:49 +08:00
|
|
|
<script>
|
|
|
|
|
async function renderRequest(path, options = {}) {
|
|
|
|
|
const box = document.getElementById('resultBox');
|
|
|
|
|
box.textContent = 'Loading ' + path + ' ...';
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(path, options);
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
box.textContent = JSON.stringify(data, null, 2);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
box.textContent = 'Request failed: ' + error.message;
|
2026-03-09 02:04:16 +08:00
|
|
|
}
|
2026-03-19 13:53:49 +08:00
|
|
|
}
|
2026-03-09 02:04:16 +08:00
|
|
|
|
2026-03-19 13:53:49 +08:00
|
|
|
async function loadUsers() {
|
|
|
|
|
await renderRequest('/api/users');
|
|
|
|
|
}
|
2026-03-09 02:04:16 +08:00
|
|
|
|
2026-03-19 13:53:49 +08:00
|
|
|
async function loadUserStats() {
|
|
|
|
|
await renderRequest('/api/users/stats');
|
|
|
|
|
}
|
2026-03-09 02:04:16 +08:00
|
|
|
|
2026-03-19 13:53:49 +08:00
|
|
|
async function loadAopStats() {
|
|
|
|
|
await renderRequest('/aop/aop/stats');
|
|
|
|
|
}
|
2026-03-09 02:04:16 +08:00
|
|
|
|
2026-03-19 13:53:49 +08:00
|
|
|
async function sendInvalidUser() {
|
|
|
|
|
await renderRequest('/api/users', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
body: JSON.stringify({ name: '', email: 'bad', age: 999 })
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
</script>
|
2026-03-07 05:43:15 +00:00
|
|
|
</body>
|
2026-03-19 13:53:49 +08:00
|
|
|
</html>
|