百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术文章 > 正文

小熊进阶之JAVA编程SSH框架整合教程,不服来吐槽!

ccwgpt 2024-09-14 00:18 97 浏览 0 评论

小熊进阶之JAVA编程SSH框架整合教程,不服来吐槽!

IDE: Eclipse Mars Release (4.5.0)

DB: MySQL 5.1.73

服务器: Tomcat 7.0

1,首先在Eclipse中新建一个Dynamic Web Project,暂且起名为SSH;

2,新建包名:

3,导入jar包:

4,配置Struts2框架:

a,在 web.xml 中配置struts2过滤器:

<filter>

<filter-name>action</filter-name>

<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

</filter>

<filter-mapping>

<filter-name>action</filter-name>

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

</filter-mapping>

b,新建config源文件夹,并在该文件夹中新建struts.xml配置文件

<?xmlversion="1.0"?>

<struts>

<packagename="shw"namespace="/"extends="struts-default">

</package>

</struts>

5,将 log4j.properties 文件复制粘贴到 config 文件夹中;

6,新建 jdbc.properties 文件在 config 文件夹中:

小熊进阶之JAVA编程SSH框架整合教程,不服来吐槽!

7,新建 hibernate.cfg.xml 文件到 config 文件夹;

<?xmlversion="1.0"?>

<!DOCTYPE hibernate-configuration PUBLIC

"-//Hibernate/Hibernate Configuration DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>

<propertyname="dialect">org.hibernate.dialect.MySQL5Dialect</property>

<propertyname="hbm2ddl.auto">update</property>

<propertyname="show_sql">true</property>

</session-factory>

</hibernate-configuration>

8,新建 ApplicationContext.xml 文件在 config 文件夹中;

<?xmlversion="1.0"?>

<beansxmlns="http://www.springframework.org/schema/beans"

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

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

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

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

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

http://www.springframework.org/schema/tx/spring-tx-3.0.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">

<!-- 组件扫描 -->

<context:component-scanbase-package="com.juyuan238.ssh.dao.impl,com.juyuan238.ssh.service.impl,com.juyuan238.ssh.web"/>

<!-- 分散配置 -->

<context:property-placeholderlocation="classpath:jdbc.properties"/>

<!-- 数据源 -->

<beanid="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource">

<propertyname="driverClass"value="${jdbc.driverclass}"/>

<propertyname="jdbcUrl"value="${jdbc.url}"/>

<propertyname="user"value="${jdbc.username}"/>

<propertyname="password"value="${jdbc.password}"/>

<propertyname="maxPoolSize"value="${c3p0.pool.size.max}"/>

<propertyname="minPoolSize"value="${c3p0.pool.size.min}"/>

<propertyname="initialPoolSize"value="${c3p0.pool.size.ini}"/>

<propertyname="acquireIncrement"value="${c3p0.pool.size.increment}"/>

</bean>

<!-- 本地会话工厂bean,spring整合hibernate的核心入口 -->

<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

<!-- 注入数据源 -->

<propertyname="dataSource"ref="dataSource"/>

<!-- 指定hibernate配置文件 -->

<propertyname="configLocation"value="classpath:hibernate.cfg.xml"/>

<!-- 指定映射文件目录 -->

<propertyname="mappingDirectoryLocations">

<list>

<value>classpath:com/juyuan238/ssh/domin</value>

</list>

</property>

</bean>

<!-- 事务管理器,在service层面上实现事务管理,而且达到平台无关性 -->

<beanid="txManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager">

<propertyname="sessionFactory"ref="sessionFactory"/>

</bean>

<!-- 配置事务通知 -->

<tx:adviceid="txAdvice"transaction-manager="txManager">

<tx:attributes>

<tx:methodname="save*"propagation="REQUIRED"isolation="DEFAULT"/>

<tx:methodname="update*"propagation="REQUIRED"isolation="DEFAULT"/>

<tx:methodname="delete*"propagation="REQUIRED"isolation="DEFAULT"/>

<tx:methodname="batch*"propagation="REQUIRED"isolation="DEFAULT"/>

<tx:methodname="new*"propagation="REQUIRED"isolation="DEFAULT"/>

<tx:methodname="get*"propagation="REQUIRED"isolation="DEFAULT"read-only="true"/>

<tx:methodname="load*"propagation="REQUIRED"isolation="DEFAULT"read-only="true"/>

<tx:methodname="find*"propagation="REQUIRED"isolation="DEFAULT"read-only="true"/>

<tx:methodname="*"propagation="REQUIRED"isolation="DEFAULT"/>

</tx:attributes>

</tx:advice>

<!-- aop事务配置 -->

<aop:config>

<aop:advisoradvice-ref="txAdvice"pointcut="execution(* *..*Service.*(..))"/>

</aop:config>

</beans>

9,配置 Spring 的监听器在 web.xml 中;

小熊进阶之JAVA编程SSH框架整合教程,不服来吐槽!

10,新建测试类,测试数据源:

小熊进阶之JAVA编程SSH框架整合教程,不服来吐槽!

注: 如果正常的话,控制台会打印出信息如下:

小熊进阶之JAVA编程SSH框架整合教程,不服来吐槽!

11,接下来的话,我们再来测试下发布成 web 应用时,框架是否能正确运行:

a,在 com.juyuan238.ssh.web 中新建一个类,暂且起名为: ShwAction

@Controller("shwAction")

publicclass ShwAction {

public String index(){

return"load";

}

}

b,到 struts2 配置文件 struts.xml 中,编写配置文件:

<struts>

<packagename="struts2"namespace="/"extends="struts-default">

<actionname="shw"class="shwAction"method="{1}">

<resultname="load">WEB-INF/jsp/success.jsp</result>

</action>

</package>

</struts>

c,在WEB-INF 目录下新建 jsp 文件夹,并在 jsp 文件夹中新建 success.jsp ;

小熊进阶之JAVA编程SSH框架整合教程,不服来吐槽!

注: 新建 jsp 页面的时候,可能会发现 jsp 页面报错,没事,这是正常的。解决办法如下 :

右键当前项目---->Build Path---->Configure Build Path----->切换到" Libraries "------>Add Libray----->Server Runtime------->选择相应的" Tomcat "版本---->finish----->OK

d,在 index.jsp 中添加超链接:

小熊进阶之JAVA编程SSH框架整合教程,不服来吐槽!

e,将项目部署到 tomcat 中,并启动 tomcat 服务器;

f,点击链接,如果能够链接到 success.jsp 页面,说明框架整合成功!否则的话,就要继续努力了……

好了,三大框架的整合说到这里就已经结束了,希望对大家能够有所帮助……

欢迎大家在下方积极吐槽,小编会一一进行查看并回复,期待你的答案哦……

-------------------------------------------------

小熊原创,如果喜欢请转发,小小支持一下。

更多精彩文章请关注 本头条号(小熊学IT ) 或 微信公众号 ITDetail(小熊学IT ),更有机会联系小熊为你在IT行业的答疑解惑……

相关推荐

十分钟让你学会LNMP架构负载均衡(impala负载均衡)

业务架构、应用架构、数据架构和技术架构一、几个基本概念1、pv值pv值(pageviews):页面的浏览量概念:一个网站的所有页面,在一天内,被浏览的总次数。(大型网站通常是上千万的级别)2、u...

AGV仓储机器人调度系统架构(agv物流机器人)

系统架构层次划分采用分层模块化设计,分为以下五层:1.1用户接口层功能:提供人机交互界面(Web/桌面端),支持任务下发、实时监控、数据可视化和报警管理。模块:任务管理面板:接收订单(如拣货、...

远程热部署在美团的落地实践(远程热点是什么意思)

Sonic是美团内部研发设计的一款用于热部署的IDEA插件,本文其实现原理及落地的一些技术细节。在阅读本文之前,建议大家先熟悉一下Spring源码、SpringMVC源码、SpringBoot...

springboot搭建xxl-job(分布式任务调度系统)

一、部署xxl-job服务端下载xxl-job源码:https://gitee.com/xuxueli0323/xxl-job二、导入项目、创建xxl_job数据库、修改配置文件为自己的数据库三、启动...

大模型:使用vLLM和Ray分布式部署推理应用

一、vLLM:面向大模型的高效推理框架1.核心特点专为推理优化:专注于大模型(如GPT-3、LLaMA)的高吞吐量、低延迟推理。关键技术:PagedAttention:类似操作系统内存分页管理,将K...

国产开源之光【分布式工作流调度系统】:DolphinScheduler

DolphinScheduler是一个开源的分布式工作流调度系统,旨在帮助用户以可靠、高效和可扩展的方式管理和调度大规模的数据处理工作流。它支持以图形化方式定义和管理工作流,提供了丰富的调度功能和监控...

简单可靠高效的分布式任务队列系统

#记录我的2024#大家好,又见面了,我是GitHub精选君!背景介绍在系统访问量逐渐增大,高并发、分布式系统成为了企业技术架构升级的必由之路。在这样的背景下,异步任务队列扮演着至关重要的角色,...

虚拟服务器之间如何分布式运行?(虚拟服务器部署)

  在云计算和虚拟化技术快速发展的今天,传统“单机单任务”的服务器架构早已难以满足现代业务对高并发、高可用、弹性伸缩和容错容灾的严苛要求。分布式系统应运而生,并成为支撑各类互联网平台、企业信息系统和A...

一文掌握 XXL-Job 的 6 大核心组件

XXL-Job是一个分布式任务调度平台,其核心组件主要包括以下部分,各组件相互协作实现高效的任务调度与管理:1.调度注册中心(RegistryCenter)作用:负责管理调度器(Schedule...

京东大佬问我,SpringBoot中如何做延迟队列?单机与分布式如何做?

京东大佬问我,SpringBoot中如何做延迟队列?单机如何做?分布式如何做呢?并给出案例与代码分析。嗯,用户问的是在SpringBoot中如何实现延迟队列,单机和分布式环境下分别怎么做。这个问题其实...

企业级项目组件选型(一)分布式任务调度平台

官网地址:https://www.xuxueli.com/xxl-job/能力介绍架构图安全性为提升系统安全性,调度中心和执行器进行安全性校验,双方AccessToken匹配才允许通讯;调度中心和执...

python多进程的分布式任务调度应用场景及示例

多进程的分布式任务调度可以应用于以下场景:分布式爬虫:importmultiprocessingimportrequestsdefcrawl(url):response=re...

SpringBoot整合ElasticJob实现分布式任务调度

介绍ElasticJob是面向互联网生态和海量任务的分布式调度解决方案,由两个相互独立的子项目ElasticJob-Lite和ElasticJob-Cloud组成。它通过弹性调度、资源管控、...

分布式可视化 DAG 任务调度系统 Taier 的整体流程分析

Taier作为袋鼠云的开源项目之一,是一个分布式可视化的DAG任务调度系统。旨在降低ETL开发成本,提高大数据平台稳定性,让大数据开发人员可以在Taier直接进行业务逻辑的开发,而不用关...

SpringBoot任务调度:@Scheduled与TaskExecutor全面解析

一、任务调度基础概念1.1什么是任务调度任务调度是指按照预定的时间计划或特定条件自动执行任务的过程。在现代应用开发中,任务调度扮演着至关重要的角色,它使得开发者能够自动化处理周期性任务、定时任务和异...

取消回复欢迎 发表评论: