l;
@Value("${spring.datasource.driver}")
private String driver;
@Value("${spring.datasource.user}")
private String user;
@Value("${spring.datasource.password}")
private String password;
@Value("${spring.web.view.prefix}")
private String webViewPrefix;
@Value("${spring.web.view.suffix}")
private String webViewSuffix;
@Value("${spring.web.static.handler}")
private String webStaticHandler;
@Value("${spring.web.static.resource}")
private String webStaticResource;
@Value("${spring.web.static.cache.period}")
private Integer webStaticCachedPeriod;
@Value("${mybatis.type.alias.package}")
private String mybatisTypeAliasPackage;
public String getWebViewPrefix() {
return webViewPrefix;
}
public String getWebViewSuffix() {
return webViewSuffix;
}
public String getWebStaticHandler() {
return webStaticHandler;
}
public String getWebStaticResource() {
return webStaticResource;
}
public Integer getWebStaticCachedPeriod() {
return webStaticCachedPeriod;
}
public String getMybatisTypeAliasPackage() {
return mybatisTypeAliasPackage;
}
public String getUrl() {
return url;
}
public String getDriver() {
return driver;
}
public String getUser() {
return user;
}
public String getPassword() {
return password;
}
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
此处用于读取application.properties的文件内容 注意@Value与@PropertySource的含义
4.MyWebAppInitializer
package com.bdqn.lyrk.ssm.study.config;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import javax.servlet.Filter;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
/**
* 初始化servlet WebApplicationContext 相关
*
* @author chen.nie
* @date 2017/12/28
**/
public class MyWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[]{AppConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[]{Dispatche