JavaWeb:service层

service(业务逻辑层),由于依赖是传递的,所以需要依赖dao层;
JavaWeb:service层_第1张图片

  • pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>###根模块名称###artifactId>
        <groupId>###groupId名称###groupId>
        <version>1.0-SNAPSHOTversion>
    parent>
    <modelVersion>4.0.0modelVersion>
    <artifactId>###service层模块名称###artifactId>

    <dependencies>
        
        <dependency>
            <groupId>###groupId名称###groupId>
            <artifactId>###依赖dao层名称###artifactId>
            <version>1.0-SNAPSHOTversion>
        dependency>
    dependencies>

    <build>
        <resources>
            
            <resource>
                <directory>src/main/javadirectory>
                <includes>
                    <include>**/*.propertiesinclude>
                    <include>**/*.xmlinclude>
                includes>
                <filtering>falsefiltering>
            resource>
            <resource>
                <directory>src/main/resourcesdirectory>
                <includes>
                    <include>**/*.propertiesinclude>
                    <include>**/*.xmlinclude>
                includes>
                <filtering>falsefiltering>
            resource>
        resources>
    build>
project>
  • 在service模块的src/main/resources/目录下新建一个spring目录,然后新建 applicationContext-serivce.xml 文件

<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.2.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.2.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">

    
    <context:component-scan base-package="cn.edu.zzti.cs.service.**"/>

    
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="**" propagation="REQUIRED" />
        tx:attributes>
    tx:advice>

    
    <aop:config proxy-target-class="true">
        <aop:pointcut id="serviceMethod" expression="(execution(* cn.edu.zzti.cs.service.*..*(..)))"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod"/>
    aop:config>

    
    

beans>
  • 配置IDE的spring应用上下文

你可能感兴趣的:(JavaEEstudy)