ssm框架整合总体配置

1,ssm框架整合总体配置(以下6个文件放在src目录下,web.xml自己定义)

1.1   applicationContext-mybatis.xml      spring总体配置文件

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.offcn.service"/>
<context:component-scan base-package="com.offcn.dao"/>
<context:annotation-config/>
<context:property-placeholder location="classpath:database.properties"/>
 <!--  JNDI获取数据源(使用dbcp连接池)  -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" scope="singleton">
<property name="driverClassName" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${user}"/>
<property name="password" value="${password}"/>
<property name="initialSize" value="${initialSize}"/>
<property name="maxActive" value="${maxActive}"/>
<property name="maxIdle" value="${maxIdle}"/>
<property name="minIdle" value="${minIdle}"/>
<property name="maxWait" value="${maxWait}"/>
<property name="removeAbandoned" value="${removeAbandoned}"/>
<property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="60000"/>
<property name="testOnBorrow" value="false"/>
<property name="testOnReturn" value="false"/>
<property name="validationQuery" value="select 1"/>
<property name="numTestsPerEvictionRun" value="${maxActive}"/>
</bean>
 <!--  事务管理 4 大原则 1原子性2 一致性3持久性4隔离    -->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
 <!--  配置mybatis SqlSessionFactoryBean  -->
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:mybatis-config.xml"/>
</bean>
<aop:aspectj-autoproxy/>
<aop:config proxy-target-class="true">
<aop:pointcut expression="execution(* *com.offcn.service..*(..))" id="transService"/>
<aop:advisor advice-ref="myAdvice" pointcut-ref="transService"/>
</aop:config>
<tx:advice id="myAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="appsys*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.offcn.dao"/>
</bean>
</beans>

1.2  database.properties    MySQL 数据库连接配置文件

driver=com.mysql.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/tt?useUnicode=true&characterEncoding=utf-8
user=root
password=root
minIdle=45
maxIdle=50
initialSize=5
maxActive=100
maxWait=100
removeAbandonedTimeout=180
removeAbandoned=true

1.3  mybatis-config.xml     文件

<configuration>

<settings>

<!-- changes from the defaults -->

<setting name="lazyLoadingEnabled" value="false"/>

</settings>

<typeAliases>

<!-- 这里给实体类取别名,方便在mapper配置文件中使用 -->

<package name="com.offcn.entity"/>

</typeAliases>

</configuration>

1.4     springmvc-servlet.xml 文件配置(包含文件上传,下载)

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" 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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

<context:component-scan base-package="com.offcn.controller"/>
<!-- 配置json解析器 -->
<mvc:annotation-driven>

<mvc:message-converters>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">

<property name="supportedMediaTypes">

<list>

<value>application/json;charset=UTF-8</value>

</list>

</property>

</bean>

<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">

<property name="supportedMediaTypes">

<list>

<value>text/html;charset=UTF-8</value>

<value>application/json</value>

</list>

</property>

<property name="features">

<list>

<value>WriteDateUseDateFormat</value>

</list>

</property>

</bean>

</mvc:message-converters>

</mvc:annotation-driven>

<mvc:resources location="/statics/" mapping="/statics/**"/>

<!-- 配置多视图解析器 -->

<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">

<property name="favorParameter" value="true"/>

<property name="defaultContentType" value="text/html"/>

<property name="mediaTypes">

<map>

<entry key="html" value="text/html; charset=UTF-8"/>

<entry key="json" value="application/json; charset=UTF-8"/>

<entry key="xml" value="application/xml; charset=UTF-8"/>

</map>

</property>

<property name="viewResolvers">

<list>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="prefix" value="/"/>

<property name="suffix" value=".jsp"/>

</bean>

</list>

</property>

</bean>

<!-- 配置interceptors -->

<!--

<mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/manager/backend/**"/> <mvc:mapping path="/dev/flatform/**"/> <bean class="cn.appsys.interceptor.SysInterceptor"/> </mvc:interceptor> </mvc:interceptors>

-->

<!-- 配置文件上传 MultipartResolver -->

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

<property name="maxUploadSize" value="500000000"/>

<property name="defaultEncoding" value="UTF-8"/>

</bean>

</beans>

1.5  UserMapper.xml (自定义的dao层)

<mapper namespace="com.offcn.dao.UserMapper">

<select id="getLoginUser" resultType="User">

select u.* from `user` u

<trim prefix="where" prefixOverrides="and | or">

<if test="uname != null"> and u.uname = #{uname} </if>

</trim>

</select>

</mapper>

1.6  web.xml 文件

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0">

<welcome-file-list>

<welcome-file>index.jsp</welcome-file>

</welcome-file-list>

<!--

指定Spring Bean的配置文件所在目录 在web.xml中通过contextConfigLocation配置spring, contextConfigLocation参数定义了要装入的 Spring 配置文件。

-->

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:applicationContext-*.xml</param-value>

</context-param>

<!-- spring字符编码过滤器start -->

<filter>

<!-- ① Spring 编码过滤器 -->

<filter-name>encodingFilter</filter-name>

<filter-class>

org.springframework.web.filter.CharacterEncodingFilter

</filter-class>

<!-- ② 编码方式 -->

<init-param>

<param-name>encoding</param-name>

<param-value>UTF-8</param-value>

</init-param>

<!-- ③ 强制进行编码转换 -->

<init-param>

<param-name>forceEncoding</param-name>

<param-value>true</param-value>

</init-param>

</filter>

<!-- ② 过滤器的匹配 URL -->

<filter-mapping>

<filter-name>encodingFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

<!-- spring字符编码过滤器end -->

<!-- Spring MVC配置 -->

<servlet>

<servlet-name>spring</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:springmvc-servlet.xml</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>spring</servlet-name>

<url-pattern>/</url-pattern>

</servlet-mapping>

<!-- Spring配置 -->

<!-- 当系统启动的时候,spring需要进行一些资源加载或者配置,都需要使用此监听去做 -->

<listener>

<listener-class>

org.springframework.web.context.ContextLoaderListener

</listener-class>

</listener>

<!-- log4j配置start -->

<context-param>

<param-name>log4jConfigLocation</param-name>

<param-value>classpath:log4j.properties</param-value>

</context-param>

<!-- Spring 加载 Log4j 的监听 -->

<listener>

<listener-class> org.springframework.web.util.Log4jConfigListener </listener-class>

</listener>

<!-- log4j配置end -->

</web-app>

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
图像识别技术在病虫害检测中的应用是一个快速发展的领域,它结合了计算机视觉和机器学习算法来自动识别和分类植物上的病虫害。以下是这一技术的一些关键步骤和组成部分: 1. **数据收集**:首先需要收集大量的植物图像数据,这些数据包括健康植物的图像以及受不同病虫害影响的植物图像。 2. **图像预处理**:对收集到的图像进行处理,以提高后续分析的准确性。这可能包括调整亮度、对比度、去噪、裁剪、缩放等。 3. **特征提取**:从图像中提取有助于识别病虫害的特征。这些特征可能包括颜色、纹理、形状、边缘等。 4. **模型训练**:使用机器学习算法(如支持向量机、随机森林、卷积神经网络等)来训练模型。训练过程中,算法会学习如何根据提取的特征来识别不同的病虫害。 5. **模型验证和测试**:在独立的测试集上验证模型的性能,以确保其准确性和泛化能力。 6. **部署和应用**:将训练好的模型部署到实际的病虫害检测系统中,可以是移动应用、网页服务或集成到智能农业设备中。 7. **实时监测**:在实际应用中,系统可以实时接收植物图像,并快速给出病虫害的检测结果。 8. **持续学习**:随着时间的推移,系统可以不断学习新的病虫害样本,以提高其识别能力。 9. **用户界面**:为了方便用户使用,通常会有一个用户友好的界面,显示检测结果,并提供进一步的指导或建议。 这项技术的优势在于它可以快速、准确地识别出病虫害,甚至在早期阶段就能发现问题,从而及时采取措施。此外,它还可以减少对化学农药的依赖,支持可持续农业发展。随着技术的不断进步,图像识别在病虫害检测中的应用将越来越广泛。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值