51,397
社区成员




<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:annotation-config/>
<context:component-scan base-package="cn.com.utt"/>
<aop:aspectj-autoproxy proxy-target-class="true"/>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:jdbc.properties" />
</bean>
<bean id="parentDataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="mysqlDataSource" parent="parentDataSource">
<property name="url" value="${mysql.url}"/>
</bean>
<bean id="infobrightDataSource" parent="parentDataSource">
<property name="url" value="${infobright.url}" />
</bean>
<bean id="dataSource" class="cn.com.utt.source.RoutingDataSource">
<property name="targetDataSources">
<map key-type="cn.com.utt.source.DataSourceType">
<entry key="MYSQLSOURCE" value-ref="mysqlDataSource"/>
<entry key="INFOBRIGHTSOURCE" value-ref="infobrightDataSource"/>
</map>
</property>
<property name="defaultTargetDataSource" ref="mysqlDataSource"/>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
<!-- pojo映射文件 -->
<property name="annotatedClasses">
<list>
<value>cn.com.utt.pojo.Reportplot</value>
<value>cn.com.utt.pojo.Report</value>
<value>cn.com.utt.pojo.Equipstatus</value>
<value>cn.com.utt.pojo.Intfstatus</value>
<value>cn.com.utt.pojo.User</value>
<value>cn.com.utt.pojo.Emailserver</value>
<value>cn.com.utt.pojo.Receiver</value>
<value>cn.com.utt.pojo.TreeNode</value>
<value>cn.com.utt.pojo.UserNode</value>
<value>cn.com.utt.pojo.Equip</value>
<value>cn.com.utt.pojo.Smsserver</value>
<value>cn.com.utt.pojo.Monitortype</value>
<value>cn.com.utt.pojo.Alarmlog</value>
<value>cn.com.utt.pojo.Bakplot</value>
<value>cn.com.utt.pojo.EquipBak</value>
<value>cn.com.utt.pojo.ReportplotEquip</value>
<value>cn.com.utt.pojo.QuartzJob</value>
<value>cn.com.utt.pojo.Alarmplot</value>
<value>cn.com.utt.pojo.Alarmrule</value>
<value>cn.com.utt.pojo.AlarmEquip</value>
<value>cn.com.utt.pojo.AlarmrulePlot</value>
<value>cn.com.utt.pojo.AlarmruleReceiver</value>
<value>cn.com.utt.pojo.Equiplog</value>
<value>cn.com.utt.pojo.Mib</value>
<value>cn.com.utt.pojo.Config</value>
<value>cn.com.utt.pojo.ConfigDetail</value>
<value>cn.com.utt.pojo.Urllog</value>
<value>cn.com.utt.pojo.Natlog</value>
<value>cn.com.utt.pojo.IMlog</value>
<value>cn.com.utt.vo.UrlRank</value>
<value>cn.com.utt.pojo.Emaillog</value>
<value>cn.com.utt.pojo.BBSlog</value>
<value>cn.com.utt.pojo.Weibolog</value>
<value>cn.com.utt.pojo.AlarmCount</value>
<value>cn.com.utt.pojo.UrlCount</value>
<value>cn.com.utt.vo.DatasetValue</value>
</list>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="find*" read-only="true"/>
<tx:method name="query*" read-only="true"/>
<tx:method name="load*" read-only="true"/>
<tx:method name="count*" read-only="true"/>
<tx:method name="add*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="addUserNode" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
<tx:method name="list*" propagation="REQUIRED"/>
<tx:method name="get*" propagation="REQUIRED"/>
<tx:method name="copy*" propagation="REQUIRED"/>
<tx:method name="*" propagation="SUPPORTS" read-only="false" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression="execution(public * cn.com.utt.dao..*.*(..))" id="daopoint"/>
<aop:advisor pointcut-ref="daopoint" advice-ref="txAdvice"/>
</aop:config>
<!-- quartz配置 -->
<bean name="quartzScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="applicationContextSchedulerContextKey" value="applicationContextKey"/>
<property name="configLocation" value="classpath:quartz.properties"/><!--
这个是必须的,QuartzScheduler 延时启动,应用启动完后 QuartzScheduler 再启动
--><property name="startupDelay" value="30"/><!--
这个是可选,QuartzScheduler 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
--><property name="overwriteExistingJobs" value="true"/>
<property name="jobDetails" >
<list>
<ref bean="jobDetail"/>
</list>
</property>
</bean>
<!--<bean id="jobDetail" class="frameworkx.springframework.scheduling.quartz.BeanInvokingJobDetailFactoryBean">
shouldRecover属性为true,则当Quartz服务被中止后,再次启动任务时会尝试恢复执行之前未完成的所有任务
<property name="shouldRecover" value="true"/>
<property name="targetBean" value="backUpConfigAction"/>
<property name="targetMethod" value="run"/>-->
<bean id="jobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="cn.com.utt.action.ExecuteJobAction" />
<property name="jobDataAsMap">
<map>
<entry key="jobService">
<ref bean="jobService"/>
</entry>
</map>
</property>
</bean>
</beans>
@Component("testDao")
@Transactional
public class TestDaoImpl implements TestDao{
private HibernateTemplate hibernateTemplate;
public HibernateTemplate getHibernateTemplate() {
return hibernateTemplate;
}
@Resource
public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}
@Transactional(propagation=Propagation.REQUIRED,rollbackFor={Exception.class})
public void addReportplot(Reportplot reportplot) throws DataAccessException {
System.out.println("添加DAO");
this.hibernateTemplate.saveOrUpdate(reportplot);
}
@Transactional(propagation=Propagation.REQUIRED,rollbackFor={Exception.class})
public void updateReportplot(Report reportplot)
throws DataAccessException {
System.out.println("修改DAO");
this.hibernateTemplate.saveOrUpdate(reportplot);
}
}
@Component("testService")
public class TestServiceImpl implements TestService{
private TestDao testDao;
public TestDao getTestDao() {
return testDao;
}
@Resource
public void setTestDao(TestDao testDao) {
this.testDao = testDao;
}
public void addReportplot(Reportplot reportplot) {
System.out.println("添加");
testDao.addReportplot(reportplot);
}
public void updateReportplot(Report reportplot) {
System.out.println("修改");
testDao.updateReportplot(reportplot);
}
@Component("testAction")
@Scope("prototype")
public class TestAction extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
private TestService testService;
public TestService getTestService() {
return testService;
}
@Resource
public void setTestService(TestService testService) {
this.testService = testService;
}
public String execute()throws Exception{
try {
System.out.println("进入测试");
Reportplot reportplot1 = new Reportplot();
reportplot1.setName("aaaaa");
reportplot1.setStatus((byte)1);
reportplot1.setType((byte)1);
reportplot1.setCreator((long)1);
testService.addReportplot(reportplot1);
Report reportplot2 = new Report();
reportplot2.setId((long)1);
reportplot2.setReportplotid((long)1);
testService.updateReportplot(reportplot2);
} catch (Exception e) {
System.out.println("失败");
// throw new RuntimeException("aaaaaaa");
}
return "success";
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance".....>
<context:annotation-config/>
<context:component-scan base-package="cn.com.utt"/>
<aop:aspectj-autoproxy proxy-target-class="true"/>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:jdbc.properties" />
</bean>
<bean id="parentDataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="mysqlDataSource" parent="parentDataSource">
<property name="url" value="${mysql.url}"/>
</bean>
<bean id="infobrightDataSource" parent="parentDataSource">
<property name="url" value="${infobright.url}" />
</bean>
<bean id="dataSource" class="cn.com.utt.source.RoutingDataSource">
<property name="targetDataSources">
<map key-type="cn.com.utt.source.DataSourceType">
<entry key="MYSQLSOURCE" value-ref="mysqlDataSource"/>
<entry key="INFOBRIGHTSOURCE" value-ref="infobrightDataSource"/>
</map>
</property>
<property name="defaultTargetDataSource" ref="mysqlDataSource"/>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
<!-- pojo映射文件 -->
<property name="annotatedClasses">
<list>
<value>cn.com.utt.pojo.Reportplot</value>
<value>cn.com.utt.pojo.Report</value>
<value>cn.com.utt.pojo.Equipstatus</value>
<value>cn.com.utt.pojo.Intfstatus</value>
<value>cn.com.utt.pojo.User</value>
<value>cn.com.utt.pojo.Emailserver</value>
<value>cn.com.utt.pojo.Receiver</value>
<value>cn.com.utt.pojo.TreeNode</value>
<value>cn.com.utt.pojo.UserNode</value>
<value>cn.com.utt.pojo.Equip</value>
<value>cn.com.utt.pojo.Smsserver</value>
<value>cn.com.utt.pojo.Monitortype</value>
<value>cn.com.utt.pojo.Alarmlog</value>
<value>cn.com.utt.pojo.Bakplot</value>
<value>cn.com.utt.pojo.EquipBak</value>
<value>cn.com.utt.pojo.ReportplotEquip</value>
<value>cn.com.utt.pojo.QuartzJob</value>
<value>cn.com.utt.pojo.Alarmplot</value>
<value>cn.com.utt.pojo.Alarmrule</value>
<value>cn.com.utt.pojo.AlarmEquip</value>
<value>cn.com.utt.pojo.AlarmrulePlot</value>
<value>cn.com.utt.pojo.AlarmruleReceiver</value>
<value>cn.com.utt.pojo.Equiplog</value>
<value>cn.com.utt.pojo.Mib</value>
<value>cn.com.utt.pojo.Config</value>
<value>cn.com.utt.pojo.ConfigDetail</value>
<value>cn.com.utt.pojo.Urllog</value>
<value>cn.com.utt.pojo.Natlog</value>
<value>cn.com.utt.pojo.IMlog</value>
<value>cn.com.utt.vo.UrlRank</value>
<value>cn.com.utt.pojo.Emaillog</value>
<value>cn.com.utt.pojo.BBSlog</value>
<value>cn.com.utt.pojo.Weibolog</value>
<value>cn.com.utt.pojo.AlarmCount</value>
<value>cn.com.utt.pojo.UrlCount</value>
<value>cn.com.utt.vo.DatasetValue</value>
</list>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="find*" read-only="true"/>
<tx:method name="query*" read-only="true"/>
<tx:method name="load*" read-only="true"/>
<tx:method name="count*" read-only="true"/>
<tx:method name="add*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="addUserNode" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
<tx:method name="list*" propagation="REQUIRED"/>
<tx:method name="get*" propagation="REQUIRED"/>
<tx:method name="copy*" propagation="REQUIRED"/>
<tx:method name="*" propagation="SUPPORTS" read-only="false" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression="execution(public * cn.com.utt.dao..*.*(..))" id="daopoint"/>
<aop:advisor pointcut-ref="daopoint" advice-ref="txAdvice"/>
</aop:config>
<!-- quartz配置 -->
<bean name="quartzScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="applicationContextSchedulerContextKey" value="applicationContextKey"/>
<property name="configLocation" value="classpath:quartz.properties"/><!--
这个是必须的,QuartzScheduler 延时启动,应用启动完后 QuartzScheduler 再启动
--><property name="startupDelay" value="30"/><!--
这个是可选,QuartzScheduler 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
--><property name="overwriteExistingJobs" value="true"/>
<property name="jobDetails" >
<list>
<ref bean="jobDetail"/>
</list>
</property>
</bean>
<!--<bean id="jobDetail" class="frameworkx.springframework.scheduling.quartz.BeanInvokingJobDetailFactoryBean">
shouldRecover属性为true,则当Quartz服务被中止后,再次启动任务时会尝试恢复执行之前未完成的所有任务
<property name="shouldRecover" value="true"/>
<property name="targetBean" value="backUpConfigAction"/>
<property name="targetMethod" value="run"/>-->
<bean id="jobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="cn.com.utt.action.ExecuteJobAction" />
<property name="jobDataAsMap">
<map>
<entry key="jobService">
<ref bean="jobService"/>
</entry>
</map>
</property>
</bean>
</beans>
@Component("testDao")
@Transactional
public class TestDaoImpl implements TestDao{
private HibernateTemplate hibernateTemplate;
public HibernateTemplate getHibernateTemplate() {
return hibernateTemplate;
}
@Resource
public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}
@Transactional(propagation=Propagation.REQUIRED,rollbackFor={Exception.class,DataAccessException.class})
public void addReportplot(Reportplot reportplot) throws DataAccessException {
System.out.println("添加DAO");
this.hibernateTemplate.saveOrUpdate(reportplot);
}
@Transactional(propagation=Propagation.REQUIRED,rollbackFor={Exception.class,DataAccessException.class})
public void updateReportplot(Report reportplot)
throws DataAccessException {
System.out.println("修改DAO");
this.hibernateTemplate.saveOrUpdate(reportplot);
}
}
@Component("testService")
public class TestServiceImpl implements TestService{
private TestDao testDao;
public TestDao getTestDao() {
return testDao;
}
@Resource
public void setTestDao(TestDao testDao) {
this.testDao = testDao;
}
public void addReportplot() throws BusinessException {
try {
Reportplot reportplot1 = new Reportplot();
reportplot1.setName("aaaaa");
reportplot1.setStatus((byte)1);
reportplot1.setType((byte)1);
reportplot1.setCreator((long)1);
System.out.println("添加");
testDao.addReportplot(reportplot1);
Report reportplot2 = new Report();
reportplot2.setId((long)1);
reportplot2.setReportplotid((long)1);
System.out.println("修改");
testDao.updateReportplot(reportplot2);
} catch (Exception e) {
throw new BusinessException("addReportplot方法出错", e);
}
}
}
@Component("testAction")
@Scope("prototype")
public class TestAction extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
private TestService testService;
public TestService getTestService() {
return testService;
}
@Resource
public void setTestService(TestService testService) {
this.testService = testService;
}
public String execute()throws Exception{
try {
System.out.println("进入测试");
testService.addReportplot();
} catch (Exception e) {
System.out.println("失败");
}
return "success";
}
}
public void updateReportplot(Report reportplot) throws BusinessException{
try {
System.out.println("修改");
testDao.updateReportplot(reportplot);
} catch (Exception e) {
throw new BusinessException("countAllAlarmReport方法出错", e);
}
}