框架文件的几个重点说明:
web.xml
1,配置监听,过滤器,servlet listener -> filter -> servlet(加载顺序)
2,配置监听器,过滤器,servlet需要的配置文件(<context-param>可以多个)
3,1中的这几个结合配置文件去初始化相应的配置
4,配置欢迎或错误页面
注意一些配置的先后顺序:
比如单点退出的配置要放在字符编码的后面,否则会出现乱码(字符编码监听应放在最前面)
其他的配置文件
按照dubbo的方式划分的话,跟事物,数据库,缓存有关的配置可以放在服务提供方,控制跳转,视图解析有关的放在消费端(服务端消费端都是web工程)
<mvc:annotation-driven />主要是用来帮助我们处理请求映射,决定是哪个controller的哪个方法来处理当前请求,异常处理。类似有<task:annotation-driven />,<tx:annotation-driven transaction-manager="transactionManager" />,<cache:annotation-driven />
context:component-scan用来扫描该包内被@Repository @Service @Controller的注解类,然后注册到工厂中。并且context:component-scan激活@ required。
@ resource,@ autowired、@PostConstruct @PreDestroy @PersistenceContext @PersistenceUnit。使得在适用该bean的时候用@Autowired就行了。
<!-- 启动包扫描功能,根据下面配置的路径扫描包成为spring的bean http://blog.csdn.net/chunqiuwei/article/details/16115135 -->
<context:component-scan base-package="com.esteel" use-default-filters="false">
<context:include-filter type="regex" expression="com.esteel.*.controller.*" />
<context:include-filter type="regex" expression="com.esteel.*.service.impl.*" />
<context:include-filter type="regex" expression="com.esteel.dao.impl.*" />
<context:include-filter type="regex" expression="com.esteel.*.bean.*" />
<context:include-filter type="regex" expression="com.esteel.filter.*" />
<context:include-filter type="regex" expression="com.esteel.redis.*" />
<context:include-filter type="regex" expression="com.esteel.job.*" />
</context:component-scan>
注多处有context:component-scan用并集
context:property-placeholder .properties文件的占位使用
到此spring的前置功能就基本配置好,剩下的就是集成其他的框架的配置
<task:annotation-driven />定时任务注解扫描开启
<import resource="dubbo-consumer.xml" />引入其他配置文件
<tx:annotation-driven transaction-manager="transactionManager" /> 事物扫面注解开启
<cache:annotation-driven /><!-- 开启缓存注解 -->
即不同作用的注解需要分别开启
shrio的配置:
有直接写在文件中的过滤路径,也有通过动态注入实现过滤路径数据的动态加载
动态注入:
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="filterChainDefinitionMap" ref="chainDefinitionSectionMetaSource" />
</bean>
<bean id="chainDefinitionSectionMetaSource" class="com.esteel.common.ChainDefinitionSectionMetaSource">
<property name="filterChainDefinitions">
<value>
/admin/ = anon
/index/ = anon
/index = anon
/login = anon
/logout = logout
/getRandomValidateCode = anon
/verifyCode = anon
/admin/** = anon
/main**=authc
/ui/info**=authc
/ui/listUser**=authc,perms[admin:manage]
/dwzIndex**=authc,perms[admin:manage]
</value>
</property>
</bean>
直接写在配置文件里面:
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="filterChainDefinitions">
<value>
/information/news/getNewsInfoById==anon
/information/news/getInfoNewsData==anon
/information/news/getTopNewsData==anon
</value>
</property>
</bean>
如果不在xml中引入配置文件也可在java代码中直接用
public class TFSUtil {
static ApplicationContext context = new ClassPathXmlApplicationContext("config_spring/TFS.xml");
private static TfsManager getTfSManager() {
return (TfsManager) context.getBean("tfsManager");
}
private static String getFileExt(String fileName) {
return fileName.substring(fileName.lastIndexOf("."));
}
private static String getFileExt(String fileName) {
return fileName.substring(fileName.lastIndexOf("."));
}
/*存储文件后返回在TFS中存储的文件码*/
public static /*synchronized*/ String saveTfsByteFile(byte[] fileBytes, String fileName) {
TfsManager tfsManager = getTfSManager();
String fileExt = getFileExt(fileName);
String tfsfileName = tfsManager.saveFile(fileBytes, null, fileExt, true);
return tfsfileName;
}
}
jar包,监听,配置文件,应用
jar包,配置文件,应用