Several key notes of the framework document

A few highlights of the framework file:

 

web.xml

1. Configure listener, filter, servlet listener -> filter -> servlet (loading order)

2. Configure listeners, filters, and configuration files required by servlet (<context-param> can be multiple)

3,1 of these are combined with the configuration file to initialize the corresponding configuration

4. Configure welcome or error page

Note the order of some configurations:

For example, the configuration of single-point exit should be placed after the character encoding, otherwise there will be garbled characters (the character encoding monitoring should be placed at the top)

 

other configuration files

 

If it is divided according to the dubbo method, the configuration related to things, databases, and caches can be placed on the service provider, control jumps, and view resolution related on the consumer side (the server consumer side is all web projects)

 

<mvc:annotation-driven /> is mainly used to help us process request mapping, decide which controller and which method to process the current request, and handle exceptions. Similar to <task:annotation-driven />, <tx:annotation-driven transaction-manager="transactionManager" />, <cache:annotation-driven />

context:component-scan is used to scan the annotated classes of @Repository @Service @Controller in the package, and then register them with the factory. And context:component-scan activates @required.

@resource, @autowired, @PostConstruct @PreDestroy @PersistenceContext @PersistenceUnit. It is enough to use @Autowired when applying the bean.

 

 <!-- Start the package scanning function, scan the package to become a spring bean according to the path configured below 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>

 

Note that there are many places where context:component-scan uses union

 

context:property-placeholder .properties file placeholder usage

 

At this point, the pre-function of spring is basically configured, and the rest is to integrate the configuration of other frameworks.

 

<task:annotation-driven />Timed task annotation scanning is enabled

<import resource="dubbo-consumer.xml" />Import other configuration files

<tx:annotation-driven transaction-manager="transactionManager" /> transaction scan annotation is enabled

 <cache:annotation-driven /><!-- enable cache annotations-->

 That is, annotations with different functions need to be opened separately

 

shrio configuration:

There are filter paths written directly in the file, and there are also dynamic loading of filter path data through dynamic injection

 

Dynamic injection:

<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>   

 

Write it directly in the configuration file:

<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>

 

 

 

 

 

 

If you do not introduce configuration files in xml, you can also use them directly in java code

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("."));

}

 

/* Return the file code stored in TFS after storing the file */

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 package, monitor, configuration file, application

jar package, configuration file, application

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326363812&siteId=291194637