applicationContext.xml configuration details

applicationContext.xml configuration details

applicationContext.xml header configuration details:

xml version information:

<?xml version="1.0" encoding="UTF-8"?>

Default namespace: represents the default namespace for all tags that do not use other namespaces

xmlns="http://www.springframework.org/schema/beans"	

xsi standard namespace, which is used to specify the schema file of the custom namespace. The schemaLocation attribute can be used when declared.

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"	

Declare an xml schema instance. After declaration, you can use schemaLocation

xmlns:util: configuration set, constant

xmlns:jee: dealing with javeee standard related issues

xmlns:lang: store the objects in the dynamic language in the Spring container in the form of beans

xmlns:jdbc: simple encapsulation of JDBC

xmlns:aop: when using aop aspect oriented programming of spring framework, aop resources are introduced into xml files

Xmlns: TX: Spring transaction configuration

Default lazy init: this parameter indicates delayed loading, that is, annotated bean s will not be instantiated when the project is started, unless needed when the project is started. Uninitialized annotation objects will be injected into the call only when the program actually accesses the call. The default is false.

Details of applicationContext configuration file:

Context: annotation config: it is used to activate the annotations on the beans that have been registered in the spring container, that is, the displayed annotations registered with spring can only work on the beans that have been registered.

Ignore unresolved: ignore unresolved properties

Testonmirror: if true (false by default), when the application applies for a connection to the connection pool, the connection pool will judge whether the connection is available.

testOnReturn:

testWhileIdle:

classpath: is an environment variable used by the JVM to indicate how the JVM searches for class

classpath *: contains not only the class path, but also the jar file (class path) for searching

${}: EL expression that represents the value passed from another page

ref attribute: used to set the value of an object's attribute

Ref tag: used to reference another bean: < ref bean = "viewresolver" / >

applicationContext.xml configuration file complete code:

Read only: read only transaction

The proxy target class attribute value determines whether an interface based or class based proxy is created. First, explain the difference between proxy target class = "true" and proxy target class = "false". If it is true, the class based proxy will work (cglib library is required). If it is false or omitted, the standard JDK interface based proxy will work.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd"
	default-lazy-init="true">
	 <!-- Is used to activate those already in spring Registered in the container bean The above annotation, that is, the direction displayed Spring register -->
	<context:annotation-config />
	
	<!-- scanning service,dao -->
	<context:component-scan base-package="com" />
	
	<!-- Configure database connection pool -->
	<context:property-placeholder location="classpath:jdbc.properties" ignore-unresolvable="true"/>

	<!-- base dataSource -->
	<bean name="baseDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init"
		destroy-method="close">
		<!-- Configure initialization size, min, Max --> 
		<property name="initialSize" value="5" />
		<property name="maxActive" value="100" />
		<property name="minIdle" value="10" />
		<!-- Configure the time to get the connection wait timeout --> 
		<property name="maxWait" value="60000" />
		 <!-- Verify that the connection is valid SQL,Different data configurations are different --> 
		<property name="validationQuery" value="SELECT 'x'" />
		 <!-- It is recommended to configure as TRUE,Prevent fetched connections from being unavailable --> 
		<property name="testOnBorrow" value="true" />
		<property name="testOnReturn" value="true" />
		<property name="testWhileIdle" value="true" />
		 <!-- Configure how often to detect idle connections that need to be closed. The unit is milliseconds --> 
		<property name="timeBetweenEvictionRunsMillis" value="60000" />
		<!-- Configure the minimum lifetime of a connection in the pool, in milliseconds --> 
		<property name="minEvictableIdleTimeMillis" value="300000" />
		 <!-- Recycle when time limit is exceeded --> 
		<property name="removeAbandoned" value="true" />
		 <!-- Timeout; The unit is seconds. 180 seconds=3 minute --> 
		<property name="removeAbandonedTimeout" value="1800" />
		
		<property name="logAbandoned" value="true" />
		<property name="filters" value="mergeStat" />
	</bean>

 <!--   Database link address -->
	<bean name="master-dataSource" parent="baseDataSource"
		init-method="init">
		<property name="url" value="${master_driverUrl}" />
		<property name="username" value="${master_username}" />
		<property name="password" value="${master_password}" />
	</bean>


	<!-- spring integration mybatis (mybatis-spring Project (integration) -->
	<bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean">
		<!-- Configure data sources -->
		<property name="dataSource" ref="master-dataSource"></property>
		<!-- appoint mybatis configuration file -->
		<property name="configLocation" value="classpath:mybatis-config.xml"></property>
		<!-- typeAliasesPackage: The entity path corresponding to the wildcard scanning path is supported-->
		<property name="typeAliasesPackage" value="com.*.entity" />
		<!-- classpath: default resources Path corresponding xml File path-->
		<property name="mapperLocations">
			<list>
				<value>classpath*:mapper/*/*.xml</value>
			</list>
		</property>
		 <!--Inject Global mybatis The policy configuration is configured below globalConfig-->
    	<property name="globalConfig" ref="globalConfig" />
	</bean>

	<!-- MyBatis Dynamic implementation -->
	<bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<!-- yes Dao The interface is implemented dynamically. You need to know where the interface is -->
		<property name="basePackage" value="com.*.dao" />
	</bean>
	
	<!-- definition MP Global policy -->
	<bean id="globalConfig" class="com.baomidou.mybatisplus.entity.GlobalConfiguration">
	    <!-- The following three parameters are defined for logical deletion-->
	   <!--  <property name="sqlInjector" ref="logicSqlInjector" />
	    <property name="logicDeleteValue" value="-1" />
	    <property name="logicNotDeleteValue" value="1" /> -->
	    <!-- overall situation ID Type: 0, "database ID Self increasing", 1, "User input ID", 2, "Globally unique ID", 3, "Globally unique ID"-->
	    <property name="idType" value="0" />
	    <property name="dbColumnUnderline" value="false" />
	    
	</bean>

	<!-- transaction management -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="master-dataSource"></property>
	</bean>

	<!-- Transaction management properties -->
	<tx:advice id="transactionAdvice" transaction-manager="transactionManager" >
		<tx:attributes>
		<!--7 Transaction configuration
		    REQUIRED: The current transaction is supported. If there is no current transaction, a new transaction will be created. This is the most common choice. 
 			SUPPORTS: The current transaction is supported. If there is no current transaction, it will be executed in a non transaction manner. 
			MANDATORY: Supports the current transaction. If there is no current transaction, an exception will be thrown. 
			REQUIRES_NEW: Create a new transaction. If there is a current transaction, suspend the current transaction. 
			NOT_SUPPORTED: Perform operations in a non transactional manner. If there is a transaction currently, suspend the current transaction. 
			NEVER: Execute in a non transactional manner. If a transaction currently exists, an exception will be thrown. 
			NESTED: The current transaction is supported. If the current transaction exists, a nested transaction will be executed. If there is no current transaction, a new transaction will be created -->
            <tx:method name="update*" propagation="REQUIRED"/>
            <tx:method name="insert*" propagation="REQUIRED"/>
            <tx:method name="delete*" propagation="REQUIRED"/>
			<tx:method name="select*" propagation="REQUIRED" read-only="true"/>
		</tx:attributes>
	</tx:advice>
	
	<!-- AOP Configure section -->
	<aop:config proxy-target-class="true">
		<aop:advisor advice-ref="transactionAdvice" 
			pointcut="execution(* *.service..*.*(..))" />
	</aop:config>
	<aop:aspectj-autoproxy proxy-target-class="true" />
	
	
</beans>

Keywords: Java MySQL Spring

Added by dcace on Sat, 22 Jan 2022 23:15:09 +0200