org.springframework.web.servlet.config.annotation.WebMvcConfigurer@EnableWebMvc
@Configuration
@EnableTransactionManagement
@PropertySource("classpath:app_custom.properties")
@ComponentScan(basePackages={"com.twl.xg.controller","com.twl.xg.service","com.twl.xg.dao","com.twl.xg.domain","com.twl.xg.service.mock_impl","com.twl.xg.service.impl"})
public class AppConfig
extends java.lang.Object
implements org.springframework.web.servlet.config.annotation.WebMvcConfigurer
WebMvcConfigurerAdapter to do this, but since we are using Spring 5,
which supports Java 8, the empty implementations of configuration methods has been moved
to WebMvcConfigurer interface, we just need to implement this interface.
Also, we register the dataTypeList bean in this class.
| Modifier and Type | Field | Description |
|---|---|---|
private org.springframework.core.env.Environment |
env |
|
private static org.apache.log4j.Logger |
logger |
|
private PropertyService |
propertyService |
| Constructor | Description |
|---|---|
AppConfig() |
| Modifier and Type | Method | Description |
|---|---|---|
java.util.List<java.lang.String> |
addBeanDataTypeList() |
Register spring bean of dataTypeList, this is the data types that we need to fetch from
each sensor.
|
void |
addResourceHandlers(org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry registry) |
Configure the ResourceHandler, enable access to static
html, js, css.etc
files in /resources/ folder. |
void |
addViewControllers(org.springframework.web.servlet.config.annotation.ViewControllerRegistry registry) |
Configure simple automated controllers pre-configured with the response
status code and/or a view to render the response body.
|
org.springframework.web.servlet.ViewResolver |
jspViewResolver() |
Create an internalResourceViewResolver bean.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddArgumentResolvers, addCorsMappings, addFormatters, addInterceptors, addReturnValueHandlers, configureAsyncSupport, configureContentNegotiation, configureDefaultServletHandling, configureHandlerExceptionResolvers, configureMessageConverters, configurePathMatch, configureViewResolvers, extendHandlerExceptionResolvers, extendMessageConverters, getMessageCodesResolver, getValidatorprivate static final org.apache.log4j.Logger logger
@Autowired private org.springframework.core.env.Environment env
@Autowired private PropertyService propertyService
@Bean public org.springframework.web.servlet.ViewResolver jspViewResolver()
WEB-INF/jsp folder.public void addViewControllers(org.springframework.web.servlet.config.annotation.ViewControllerRegistry registry)
":"
to the index page which is the index.jsp file in
WEB-INF/jsp folder.addViewControllers in interface org.springframework.web.servlet.config.annotation.WebMvcConfigurerpublic void addResourceHandlers(org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry registry)
html, js, css.etc
files in /resources/ folder.addResourceHandlers in interface org.springframework.web.servlet.config.annotation.WebMvcConfigurer@Bean("dataTypeList")
public java.util.List<java.lang.String> addBeanDataTypeList()
[temperature, humidity, lightness].
The default data type list will loaded from database first, if there is no record in database, it will be loaded from "app_custom.properties" file.
java.lang.RuntimeException - if there is no dataTypeList in either of database and properties file.