1. Which ThemeResolver implementation does Spring MVC use by default?
SessionThemeResolver
FixedThemeResolver
CookieThemeResolver
RequestThemeResolver
Why: When no custom ThemeResolver bean is configured, Spring MVC uses FixedThemeResolver. It always returns the same theme name for every request.
2. Which component uses a ThemeResolver to handle theme logic?
DispatcherServlet
ViewResolver
MessageSource
HandlerMapping
Why: DispatcherServlet looks for a ThemeResolver and uses it to find the theme for the current request.
3. What is the default theme name used by FixedThemeResolver?
main
default
style
theme
Why: The default theme name is theme. This is why a file named theme.properties is looked up on the classpath.
4. With the default theme settings, where must the theme properties file be placed?
Inside the WEB-INF/views folder only
In the same folder as the CSS file
On the classpath, for example in src/main/resources
Inside the META-INF folder of the web app
Why: The theme file is loaded from the classpath. Placing it in src/main/resources makes it available there.
5. What does a theme properties file define?
Database connection settings for the view
Java classes that are scanned for controllers
Codes (keys) with values that a view can use
URL mappings for controller methods
Why: Each property key is a theme 'code'. A view can ask for a code and get its value, such as a color, a size or a CSS file path.
6. Which JSP tag is used to read a value from the current theme?
<%@ taglib prefix="spring"
uri="http://www.springframework.org/tags"%>
<body style="background-color:
<!-- read 'background' here -->;">
<spring:property code='background'/>
<spring:style code='background'/>
<spring:theme code='background'/>
<spring:message code='background'/>
Why: The <spring:theme> tag reads the value of the given code from the current theme. <spring:message> is used for message bundles, not themes.
7. What will be the rendered output of this JSP line?
# theme.properties
background=pink
width=400px
<!-- JSP -->
<div style="width:<spring:theme code='width'/>;">Hi</div>
<div style="width:;">Hi</div>
<div style="width:pink;">Hi</div>
<div style="width:400px;">Hi</div>
<div style="width:width;">Hi</div>
Why: The tag is replaced by the value of the width code, which is 400px.
8. A theme file contains the line below. What will the link tag render as?
# theme.properties
main-css=/themes/t1/main.css
<!-- JSP -->
<link rel="stylesheet"
href="<spring:theme code='main-css'/>"/>
<link rel="stylesheet"
href=""/>
<link rel="stylesheet"
href="/main.css"/>
<link rel="stylesheet"
href="main-css"/>
<link rel="stylesheet"
href="/themes/t1/main.css"/>
Why: A theme value can be a path to a static file. The tag is replaced by that path, so the browser requests the CSS from that URL.
9. Which class level annotation turns on Spring MVC features in a Java config class?
@Configuration
// add annotation here
@ComponentScan
public class MyWebConfig
implements WebMvcConfigurer {
}
@EnableThemes
@EnableWebMvc
@EnableMvcConfig
@EnableWebTheme
Why: @EnableWebMvc enables the Spring MVC infrastructure in a Java configuration class.
10. Which method of ResourceHandlerRegistry is used to set the folder that holds static files such as CSS?
registry.addResourceHandler("/themes/**")
// set the folder here
;
.addThemeLocations("/app-themes/")
.setStaticFolder("/app-themes/")
.addResourcePath("/app-themes/")
.addResourceLocations("/app-themes/")
Why: addResourceHandler() sets the URL pattern. addResourceLocations() sets where the files are actually stored.
11. A request for /themes/t1/a.css is made. Where will Spring look for the file?
registry
.addResourceHandler("/themes/**")
.addResourceLocations("/css-files/");
/t1/a.css
/css-files/t1/a.css
/css-files/themes/t1/a.css
/themes/t1/a.css
Why: The part of the URL matched by /themes/** is added to the resource location. So t1/a.css is searched inside /css-files/.
12. Which method is used to map a URL to a view name without writing a controller?
@Override
public void addViewControllers(
ViewControllerRegistry registry) {
registry.addViewController("/")
// set the view name here
;
}
.setPage("index")
.setView("index")
.setViewName("index")
.mapToView("index")
Why: addViewController() maps the URL. setViewName() tells which view to render for it, so no controller class is needed.
13. What does this configuration do?
@Override
public void configureViewResolvers(
ViewResolverRegistry registry) {
registry.jsp();
}
It registers a JSP view resolver with the default prefix and suffix.
It copies JSP files to the classpath.
It disables all view resolvers.
It registers a theme resolver for JSP files.
Why: registry.jsp() registers a JSP view resolver. The default prefix is /WEB-INF/ and the default suffix is .jsp.
14. Which setup makes a page read its background color and width from a theme? Look at the code below.
# theme.properties
bg=pink
w=400px
<!-- page.jsp -->
<body style="background-color:
<spring:theme code='bg'/>;">
<div style="width:
<spring:theme code='w'/>;">
Text
</div>
</body>
<body style="background-color:bg;">
<div style="width:w;">
Text
</div>
</body>
<body style="background-color:;">
<div style="width:;">
Text
</div>
</body>
<body style="background-color:400px;">
<div style="width:pink;">
Text
</div>
</body>
<body style="background-color:pink;">
<div style="width:400px;">
Text
</div>
</body>
Why: Each spring:theme tag is replaced by the value of its code: bg gives pink and w gives 400px.
15. What is the status of theme support in Spring Framework 6.0 and later?
It was moved to the Spring Security module.
It works only with Thymeleaf views.
It is the recommended way to style all web pages.
It is deprecated, and CSS should be used directly.
Why: Theme support (ThemeResolver, ThemeSource and related classes) is deprecated since Spring 6.0. There is no direct replacement; plain CSS is the suggested approach.