applicationContext.xml 配置
程序员文章站
2022-05-25 10:58:46
...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>myJNDI</value>
</property>
<!-- 如果你不想使用 'java:comp/env/'前缀的话请设置下面的值为true, 默认值为false -->
<property name="resourceRef">
<value>false</value>
</property>
</bean>
<!-- datasource 从JNDI获得数据源,JNDI在应有服务器中配置 如weblogic,配置能访问远程jndi数据源 -->
<bean id="dataSource1" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>myJNDI</value>
</property>
<property name="jndiEnvironment">
<props>
<prop key="java.naming.factory.initial">
weblogic.jndi.WLInitialContextFactory </prop>
<prop key="java.naming.provider.url"> t3://192.168.0.1:7001 </prop>
<prop key="java.naming.security.principal"> weblogic </prop>
<prop key="java.naming.security.credentials"> weblogic </prop>
</props>
</property>
</bean>
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate"
singleton="true" lazy-init="default" autowire="default"
dependency-check="default">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">
weblogic.jndi.WLInitialContextFactory </prop>
<prop key="java.naming.provider.url">t3://172.16.101.42:7001</prop>
<prop key="java.naming.security.principal">weblogic</prop>
<prop key="java.naming.security.credentials">weblogic</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager"
singleton="true" lazy-init="default" autowire="default"
dependency-check="default">
<property name="jndiTemplate">
<ref local="jndiTemplate" />
</property>
<property name="userTransactionName">
<value>weblogic/transaction/UserTransaction</value>
</property>
</bean>
<!-- datasource 配置多个数据源 -->
<bean id="jndiString_1" class="java.lang.String">
<constructor-arg>
<value>java:comp/env/jndiString_1</value>
</constructor-arg>
</bean>
<bean id="jndiString_2" class="java.lang.String">
<constructor-arg>
<value>java:comp/env/jndiString_2</value>
</constructor-arg>
</bean>
<bean id="dataSource1" class="org.springframework.jndi.JndiObjectFactoryBean"
singleton="true">
<property name="jndiName">
<ref local="jndiString_1" />
</property>
</bean>
<bean id="dataSource2" class="org.springframework.jndi.JndiObjectFactoryBean"
singleton="true">
<property name="jndiName">
<ref local="jndiString_2" />
</property>
</bean>
<!-- datasource JDBC方式 连接池管理 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="url">
<value>jdbc:oracle:thin:@localhost:1521:myoracle</value>
</property>
<property name="username">
<value>scott</value>
</property>
<property name="password">
<value>tiger</value>
</property>
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="WEB-INF/sqlmap-config.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="userDAO" class="org.pa.dao.impl.UserDAOImpl">
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
</bean>
<bean id="user" class="org.pa.bean.User" />
<bean id="userListExcelView" class="org.pa.controller.UserListExcelView" />
<bean id="userService" class="org.pa.service.impl.UserServiceImpl">
<property name="userDAO" ref="userDAO"></property>
</bean>
<bean id="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController">
<description>使用它的好处是可以用来避免直接对JSP网页请求</description>
<property name="viewName">
<value>login</value>
</property>
</bean>
<bean id="tilesIndexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController">
<property name="viewName">
<value>tilesIndex</value>
</property>
</bean>
<bean id="userInfoReportController" class="org.pa.controller.UserInfoReportController">
<description>输入EXCEL报表示例控制器</description>
</bean>
<bean id="userLoginController" name="userLoginController"
class="org.pa.controller.UserLoginController">
<description>表单控制器</description>
<property name="formView" value="login">
<description>表单录入与提交失败视图逻辑名</description>
</property>
<property name="successView" value="success">
<description>提交成功显示的视图逻辑名</description>
</property>
<property name="userService" ref="userService">
<description>引用service接口对象</description>
</property>
<property name="validator">
<description>提交表单的验证器</description>
<bean class="org.pa.controller.validate.UserValidator"></bean>
</property>
</bean>
<bean id="userInfoQueryController" class="org.pa.controller.UserInfoQueryController">
<description>简单控制器</description>
</bean>
<bean id="userManagerController" class="org.pa.controller.UserManagerController">
<description>处理多个动作</description>
<property name="userService" ref="userService">
<description>引用service接口对象</description>
</property>
<property name="methodNameResolver" ref="methodNameResolver">
<description>处理多个动作通过方法名解析</description>
</property>
</bean>
<bean id="methodNameResolver"
class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
<description>多动作方法名解析器,指定控制器的方法名http://localhost:8888/SpringMVC/userManager.do?action=update时,执行update方法</description>
<property name="paramName">
<value>action</value>
</property>
</bean>
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/index.do">indexController</prop>
<prop key="/userLogin.do">userLoginController</prop>
<prop key="/userInfoQuery.do">
userInfoQueryController
</prop>
<prop key="/tilesIndex.do">tilesIndexController</prop>
<prop key="/userInfoReport.xls">
userInfoReportController
</prop>
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<description> 视图解析器index,则URL=/WEB-INF/jsp/index.jsp </description>
<property name="prefix">
<description>视图前缀为/WEB-INF/jsp/</description>
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<description>视图后缀为.JSP</description>
<value>.jsp</value>
</property>
<property name="viewClass">
<description>tiles视图解析</description>
<value>
org.springframework.web.servlet.view.tiles.TilesView
</value>
</property>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles.TilesConfigurer">
<property name="definitions">
<list>
<value>WEB-INF/tiles-defs.xml</value>
</list>
</property>
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>messages</value>
</list>
</property>
</bean>
<!-- JAVA timer 调度任务 -->
<bean id="emailReportTask" class="org.pa.timer.EmailReportTask">
<property name="userService">
<ref bean="userService" />
</property>
</bean>
<bean id="emailReportTimerTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">
<description>定义定时器</description>
<property name="timerTask">
<ref bean="emailReportTask" />
</property>
<property name="period">
<description>每5秒运行一次(1秒=1000毫秒)</description>
<value>5000</value>
</property>
</bean>
<bean class="org.springframework.scheduling.timer.TimerFactoryBean">
<description>启动定时任务列表</description>
<property name="scheduledTimerTasks">
<list>
<ref bean="emailReportTimerTask" />
</list>
</property>
</bean>
<!--
=======================================================================================
-->
<!-- Quartz 调度任务 -->
<!--
=======================================================================================
-->
<bean id="reportJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value>org.pa.quartz.EmailReportJob</value>
</property>
<property name="jobDataAsMap">
<map>
<entry key="userService">
<ref bean="userService" />
</entry>
</map>
</property>
</bean>
<!-- 与java timer一样,运行任务时间取决于服务器启动时间-->
<bean id="simpleReportTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail">
<ref bean="reportJob" />
</property>
<description>24小时运行一次,第一次在1小时之后开始运行</description>
<property name="startDelay">
<value>3600000</value>
</property>
<property name="repeatInterval">
<value>86400000</value>
</property>
</bean>
<bean id="emailReport" class="org.springframework.scheduling.quartz.CronTriggerBean">
<description>定义发送报表定时器任务</description>
<property name="jobDetail">
<ref bean="reportJob" />
</property>
<property name="cronExpression">
<description>每天22时:52分:10秒运行任务</description>
<value>10 52 22 * * ?</value>
</property>
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<description>启动定时器列表</description>
<property name="triggers">
<list>
<ref bean="emailReport" />
</list>
</property>
</bean>
</beans>
上一篇: 小白专场-树的同构-python语言实现
下一篇: 从几个抖音大号案例分析了解抖音营销