`

愚蠢的spring

阅读更多
一个啥都不做的基于spring的web应用,至少需要8个jar, common-logging,spring asm,spring core, spring expression,spring context,spring web,spring beans,spring transation

Spring 3.0第一步:加载applicationcontext.xml

在web.xml里
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>/WEB-INF/applicationContext*.xml</param-value>
	</context-param>



第二步: 加载数据源,打开Web-inf下applicationcoext.xml,这时候spring需要你再添加3个jar: apache commones dbcp,collection,pool和spring orm,jdbc,mysql驱动程序,以及hibernate相关jar: hibernate3.jar,dom4j.jar,jta.jar,slf4j的接口包和实现包,jassit和antlr

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    <!-- <bean/> definitions here -->
    <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
        <property name="url" value="jdbc:hsqldb:hsql://localhost:9001"/>
        <property name="username" value="sa"/>
        <property name="password" value=""/>
    </bean>
	
    <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="myDataSource"/>
        <property name="mappingResources">
            <list>
                <value>
                    product.hbm.xml
                </value>
            </list>
        </property>
        <property name="hibernateProperties">
            <value>
                hibernate.dialect=org.hibernate.dialect.HSQLDialect
            </value>
        </property>
    </bean>
</beans>


第三步,添加事务管理器支持.

为了增加spring事务管理器,你还得继续在你的应用中添加jar: aopalliance,aspectj,和spring aop.....

修改applicationcontext.xml的名称空间,如下
<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: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/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">


然后添加事务管理器:
   <bean id="transactionManager"
     	class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
	
    <aop:config>
        <aop:pointcut id="productServiceMethods"
         expression="execution(* product.ProductService.*(..))"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods"/>
    </aop:config>
    
	<tx:advice id="txAdvice" transaction-manager="myTxManager">
        <tx:attributes>
            <tx:method name="increasePrice*" propagation="REQUIRED"/>
            <tx:method name="someOtherBusinessMethod" propagation="REQUIRES_NEW"/>
            <tx:method name="*" propagation="SUPPORTS" read-only="true"/>
        </tx:attributes>
    </tx:advice>
    
	<bean id="myProductService" class="product.SimpleProductService">
		<property name="productDao" ref="myProductDao"/>
	</bean>
分享到:
评论
1 楼 rovanz 2010-01-30  
大姨妈 洗洗睡吧

相关推荐

    spring-batch-in-action:我制作的Spring批处理

    随着商务或其他服务系统的发展,批处理工作会增加,但是在许多情况下,Spring Batch会以愚蠢的方式使用。 Spring MVC有很多数据,但是没有太多的批处理,所以我开始组织它。内容预期的简单批处理作业审查工作执行...

    spring-mongodb-example:Spring 4 MongoDB连接入门

    将文档插入mongo db集合的愚蠢应用程序。 依赖关系经理 Maven的3.2.5 如何建造 $ cd $ mvn clean package 怎么跑 $ cd $ java -jar target/lib/spring-mongodb-0.1.0.jar 运行MongoDB服务器 $ mongod 运行MongoDB...

    弹簧依赖注入:具有Spring Boot DI(依赖注入)的Selenium自动化框架

    Spring Boot依赖项注入 概要 该项目使用spring作为依赖项注入,并在... 这里的哲学是:“保持简单,愚蠢”。 要求 Java 8,Junit 5,Maven 从命令行运行测试 mvn清洁测试。 或mvn clean test -Dtags = smoke 有用的链接

    java-docker-example:Java (Spring Boot) Docker 服务的愚蠢示例

    Docker 容器内 Spring Boot 应用程序的简单示例。 构建一个罐子: mvn clean package作为独立的 Java 应用程序运行: java -jar target/java-docker-example.jar构建泊坞窗图像: mvn docker:build作为 docker 容器...

    GLaPEP:一个愚蠢的项目赢得了 HackNY Spring 2015 Hackathon

    # GLaPEP8 当现有工具以如此友好的方式通知您问题时,很容易忽略 PEP8 风格的轻微违规。 GLaDOS 无暇顾及您的懒惰。安装GLaPEP8 仅适用于 OS X,因为它使用了“say”命令。 ### 先决条件jp2a Python库:用法./GLaPEP...

    test-rest-api:使用 spring-security 测试 Rest API 安全的代码示例

    你会发现一个愚蠢的 ReST 服务 ( ) 假装创建、获取和破坏一个世界。 这个世界列表存储在 H2 数据库中。 没什么可怕的。 我大量使用 Spring-Boot 来节省时间和代码;)。 这非常简单。 动机 我已经完成了这段代码,以...

    jayground:做护目镜的愚蠢应用

    超级简单的 Java/Spring/Gradle 应用这是一个非常简单的应用程序,我在其中执行同样简单的测试任务。 该应用程序是来自 Spring Framework 和许多其他包的简单 DB 包装器(H2 或 PostgreSQL,取决于配置文件)。 该...

    Jusqu-ou-peut-on-innover-en-classe-d-informatique:我们在计算机科学课上可以创新多远? 只是一个用于他的票务管理器的存储库,用于列出原始和愚蠢的想法。 因为这是系统上的愚蠢,但总是出乎意料!

    有趣的主意,2021年Spring 将于2021年9月的计算机教师,,将于2021/2022年开设。 在等待九月份重返学校的过程中,我将尝试一些疯狂且新颖的想法来上课(略),这与我所有中学(2002-2009)和更高学历(2009)的...

    AStupidlySimpleBlockchain:探索区块链技术概念的个人项目

    AStupidlySimpleBlockchain简单愚蠢(SS)区块链是代表愚蠢简单区块链网络上交易的各种区块的集合。该项目的目的是探索区块链技术的领域,并且并非为生产目的而设计。该项目的衍生物更稳定,实验性更小,可能是一个...

    toonfeed:卡通聚合器

    一个愚蠢的卡通信息聚合器,展示了Spring内置消息传递功能中的一些实用概念。为什么? 这个项目使我有机会尝试使用及其消息传递和控制总线概念。概述聚合来自两个来源的卡通数据: (RSS提要) (RSS提要;仅选定的...

    samarcanda:乏味的REST应用程序

    一个作者和一个位置项目在存储库中管理两种用户可以要求服务管理员-谁可以执行常规的CRUD并移动并获取物品的当前位置客户-可以读取,借用,退货并获得商品的当前位置的人服务必须版本化安全是通过Spring-Security来...

    sipa:Simpartic

    First beta version including some documentation is planned to be released within spring 2021 目录 为什么选择西帕? 我只想用Vanilla JS和HTML开发旧方法,我想直接运行和调试在浏览器中编写的代码。 创建...

    stock_trader

    股票交易员ECE 4180 2021年Spring最终项目文档要求,因此我们不必继续检查画布公告: 项目网页上的文档必须包括团队成员姓名,零件清单,原理图,源代码,照片和视频。 许多学生在面试时都以此为例,因此值得付出...

    matlab代码左移-vanderbilt-sealab-tottag-guide:一站式服务VandyTotTag

    嗨,我们是Vedant,我们很荣幸在2019年Spring和秋季学期与范德比尔特SEA实验室合作。 我们想建立一个可以传承过去一年中收集的所有知识的地方(并且Conner痴迷于干净的文档),所以我们创建了这个GitHub以帮助新的...

    Ninbot:使用JDA的OCW Discord的基于Java的Discord机器人

    Ninbot是一款Discord机器人,具有各种愚蠢的命令和动作,例如轻拍。 Ninbot是使用为OCW Discord构建的 是否想在您的Discord服务器上使用Ninbot? 将Ninbot添加到您的服务器! 想帮助开发Ninbot吗? 在进行任何...

    github-buttons:@mdo的Github Button的脚本版本

    使用该库的原因是@mdo的版本不适用于SSL,而使用iframe只是愚蠢的。 CSS之前带有.github-btn ,以增加特定性,以避免与您自己CSS发生冲突。安装软件包管理器bower和component可用于安装github-buttons。bower ...

    clustering:CLI将UMAPLeiden集群应用于值数组

    聚类 CLI将UMAP / Leiden群集应用于值数组老实说,只是一个愚蠢的前端,就可以使用UMAP将数据矩阵聚类到最近的邻居,并使用Leiden进行社区检测。之所以写这篇文章,是因为从{reticulate}传递数据很容易达到C stack ...

Global site tag (gtag.js) - Google Analytics