• java--blog


    ssm博客系统1

     

    idea配置tomcat , maven

    http://maven.apache.org/download.cgi

    <localRepository>E:kaifaapache-maven-3.6.3-binapache-maven-3.6.3 epo</localRepository>

    <mirrors> <!-- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>https://maven.aliyun.com/repository/public/</url> <mirrorOf>central</mirrorOf> </mirror> <mirror> <id>repo2</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://repo2.maven.org/maven2/</url> </mirror> <mirror> <id>ui</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://uk.maven.org/maven2/</url> </mirror> </mirrors>

     

     

    maven仓库

    https://search.maven.org/

     

    <?xml version="1.0" encoding="UTF-8"?>
    <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">
      <modelVersion>4.0.0</modelVersion>

      <groupId>com.java1234.blog</groupId>
      <artifactId>Blog1</artifactId>
      <version>1.0-SNAPSHOT</version>

      <properties>
          <maven.compiler.source>8</maven.compiler.source>
          <maven.compiler.target>8</maven.compiler.target>
      </properties>
      <dependencies>
          <!--       添加servlet支持-->
          <dependency>
              <groupId>javax.servlet.jsp</groupId>
              <artifactId>jsp-api</artifactId>
              <version>2.2.1-b03</version>
          </dependency>
          <dependency>
              <groupId>javax.servlet</groupId>
              <artifactId>javax.servlet-api</artifactId>
              <version>4.0.1</version>
          </dependency>
          <!--       添加jstl支持-->
          <dependency>
              <groupId>javax.servlet</groupId>
              <artifactId>jstl</artifactId>
              <version>1.2</version>
          </dependency>
          <!--       添加spring支持-->
          <dependency>
              <groupId>org.springframework</groupId>
              <artifactId>spring-core</artifactId>
              <version>5.3.2</version>
          </dependency>
          <dependency>
              <groupId>org.springframework</groupId>
              <artifactId>spring-beans</artifactId>
              <version>5.3.2</version>
          </dependency>
          <dependency>
              <groupId>org.springframework</groupId>
              <artifactId>spring-tx</artifactId>
              <version>5.3.2</version>
          </dependency>
          <dependency>
              <groupId>org.springframework</groupId>
              <artifactId>spring-context</artifactId>
              <version>5.3.2</version>
          </dependency>
          <dependency>
              <groupId>org.springframework</groupId>
              <artifactId>spring-context-support</artifactId>
              <version>5.3.2</version>
          </dependency>
          <dependency>
              <groupId>org.springframework</groupId>
              <artifactId>spring-web</artifactId>
              <version>5.3.2</version>
          </dependency>
          <dependency>
              <groupId>org.springframework</groupId>
              <artifactId>spring-webmvc</artifactId>
              <version>5.3.2</version>
          </dependency>
          <dependency>
              <groupId>org.springframework</groupId>
              <artifactId>spring-aop</artifactId>
              <version>5.3.2</version>
          </dependency>
          <dependency>
              <groupId>org.springframework</groupId>
              <artifactId>spring-aspects</artifactId>
              <version>5.3.2</version>
          </dependency>
          <dependency>
              <groupId>org.springframework</groupId>
              <artifactId>spring-jdbc</artifactId>
              <version>5.3.2</version>
          </dependency>
          <dependency>
              <groupId>org.mybatis</groupId>
              <artifactId>mybatis-spring</artifactId>
              <version>2.0.6</version>
          </dependency>
          <!--添加日志支持-->
          <!--       <dependency>-->
          <!--           <groupId>org.apache.logging.log4j</groupId>-->
          <!--           <artifactId>log4j</artifactId>-->
          <!--           <version>2.14.0</version>-->
          <!--           <type>pom</type>-->
          <!--       </dependency>-->
          <dependency>
              <groupId>log4j</groupId>
              <artifactId>log4j</artifactId>
              <version>1.2.17</version>
          </dependency>
          <dependency>
              <groupId>org.slf4j</groupId>
              <artifactId>slf4j-log4j12</artifactId>
              <version>2.0.0-alpha1</version>
          </dependency>

          <!--       添加mybatis支持 -->
          <dependency>
              <groupId>org.mybatis</groupId>
              <artifactId>mybatis</artifactId>
              <version>3.5.6</version>
          </dependency>

          <!--       jdbc-->
          <dependency>
              <groupId>mysql</groupId>
              <artifactId>mysql-connector-java</artifactId>
              <version>8.0.22</version>
          </dependency>

          <!--       shiro-->
          <dependency>
              <groupId>org.apache.shiro</groupId>
              <artifactId>shiro-core</artifactId>
              <version>1.7.0</version>
          </dependency>
          <dependency>
              <groupId>org.apache.shiro</groupId>
              <artifactId>shiro-web</artifactId>
              <version>1.7.0</version>
          </dependency>
          <dependency>
              <groupId>org.apache.shiro</groupId>
              <artifactId>shiro-spring</artifactId>
              <version>1.7.0</version>
          </dependency>
          <!--       百度uedit-->
          <dependency>
              <groupId>commons-fileupload</groupId>
              <artifactId>commons-fileupload</artifactId>
              <version>1.4</version>
          </dependency>
          <!--       apache 公共包-->
          <dependency>
              <groupId>commons-codec</groupId>
              <artifactId>commons-codec</artifactId>
              <version>20041127.091804</version>
          </dependency>
          <dependency>
              <groupId>commons-lang</groupId>
              <artifactId>commons-lang</artifactId>
              <version>20030203.000129</version>
          </dependency>
          <dependency>
              <groupId>commons-beanutils</groupId>
              <artifactId>commons-beanutils</artifactId>
              <version>20030211.134440</version>
          </dependency>
          <dependency>
              <groupId>commons-collections</groupId>
              <artifactId>commons-collections</artifactId>
              <version>20040616</version>
          </dependency>
          <dependency>
              <groupId>commons-logging</groupId>
              <artifactId>commons-logging</artifactId>
              <version>1.2</version>
          </dependency>
          <dependency>
              <groupId>net.sf.ezmorph</groupId>
              <artifactId>ezmorph</artifactId>
              <version>1.0.6</version>
          </dependency>
          <!--添加lucene支持-->
          <dependency>
              <groupId>org.apache.lucene</groupId>
              <artifactId>lucene-core</artifactId>
              <version>8.7.0</version>
          </dependency>
          <dependency>
              <groupId>org.apache.lucene</groupId>
              <artifactId>lucene-analyzers-common</artifactId>
              <version>8.7.0</version>
          </dependency>
          <dependency>
              <groupId>org.apache.lucene</groupId>
              <artifactId>lucene-analyzers-smartcn</artifactId>
              <version>8.7.0</version>
          </dependency>
          <dependency>
              <groupId>org.apache.lucene</groupId>
              <artifactId>lucene-queryparser</artifactId>
              <version>8.7.0</version>
          </dependency>

          <dependency>
              <groupId>org.apache.lucene</groupId>
              <artifactId>lucene-highlighter</artifactId>
              <version>8.7.0</version>
          </dependency>
          <!--添加连接池-->
          <dependency>
              <groupId>com.alibaba</groupId>
              <artifactId>druid</artifactId>
              <version>1.2.4</version>
          </dependency>
      </dependencies>
    </project>

     

    错误

    Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.2.0:generate (default-cli) on project standalone-pom: Directory Blog already exists - please run from a clean directory

     

    于解决构建maven项目中报错:Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.0.1...:的方法

    1.首先进入仓库下面repositoryorgapachemavenplugins这个目录

    2.删除目录下的maven-archetype-plugin文件夹

    3.重新加载

    No archetype found in remote catalog. Defaulting to internal catalog

    解决方案2:

    1.可以不用管【因为使用了maven模版构建项目,要从网上获取模版,然而没有找到这个模版或者网络慢,导致获取失败 】,选择File ---> 再选择Close Project,关闭项目后重启就可以了

     

     

    The selected directory is not a TomEE home

    配置tomcat server

     

    cnative-1.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform

    网上查了一下原因,应该是32位myeclipse与64位tomcat的兼容性问题,下载一个32位tcnative-1.dll 文件将原tomcat文件夹中bin文件夹里的同名文件替换,重新启动tomcat即可。

     

    tomcat 乱码:

    这种情况是tomcat的日志配置文件的编码需要修改,找到tomcat安装目录,找到conf下的logging.properties文件,将其中的encoding = UTF-8的部分全部修改为encoding = GBK

     

    20-Dec-2020 17:47:39.748 信息 [RMI TCP Connection(3)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars 至少有一个JAR被扫描用于TLD但尚未包含TLD。 为此记录器启用调试日志记录,以获取已扫描但未在其中找到TLD的完整JAR列表。 在扫描期间跳过不需要的JAR可以

     

    这个错误我遇见多次,而且每次都是同样的问题,我在这里做一个记录,以后遇到就能很快找到问题了。 严重 [RMI TCP Connection(x)-127.0.0.1] :这个错误有非常多的原因,大部分是你的代码有地方写错了,我这里“严重 [RMI TCP Connection(3)-127.0.0.1] ”这个错误遇见几次都是我的Mapper.xml文件的nameSpace写错了,以后只要遇到“严重 [RMI TCP Connection(3)-127.0.0.1]”一般情况下就是Mapper.xml文件的nameSpace写错

     

    class path resource [com/java1234/mappers/] cannot be resolved to URL because it does not exist

    这个是无法解析当前的URL,做出如下修改,classpath 后多加一个“ * ”,修复了这个错误。

    <!-- 自动扫描mappers.xml文件 -->
    <property name="mapperLocations" value="classpath:com/java1234/*/*"></property>

     

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:kaifaapache-tomcat-9.0.41-windows-x64apache-tomcat-9.0.41webappsBlog1_warWEB-INFclassescomjava1234controllerBloggerController.class]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 2 字节的 UTF-8 序列的字节 2 无效。

     

     

    别人运行的时候,出现了这个异常,这个异常,我不知道我以前有没有遇到过,怎么说,这个异常我是没有办法解决的,于是在网上找了答案,网上的答案我看着都不错,于是拿过来记录记录一下吧。

    异常:org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘XXX’

    网上说,这个异常出现的原因一般是:为注入bean失败异常

    1. 对应的bean没有添加注解

    2. 对应bean添加注解错误,例如将spring的@Service错选成dubbo的包

    3. 选择错误的自动注入办法。

    对于解决的办法,就是得重新检查你的bean的注解,以及你添加的jar包。没有固定的解决办法,因为引发的问题不唯一。

     

    Cause: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 2 字节的 UTF-8 序列的字节 2 无效。

     

    <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

     

     org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:kaifaapache-tomcat-9.0.41-windows-x64apache-tomcat-9.0.41webappsBlog1_warWEB-INFclassescomjava1234controllerBloggerController.class]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 2 字节的 UTF-8 序列的字节 2 无效。

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'taskAction': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.as.service.TaskService org.as.web.controller.TaskAction.taskService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.as.service.TaskService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

    由以上的错误的代码可以看到,我们出现此类bug的原因:找到不到对应的bean,bean注入失败。

     

    注入失败的原因主要有:

    1.没有添加注解。例如:@Service @Autowired @Controller

    2.错误的注入方法

    3.对于web.xml中监听器的xml配置错误。

    所以我们要解决此问题,主要检查注解正确的添加,包引入是否正确,以及检查web.xml监听器的配置。

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:kaifaapache-tomcat-9.0.41-windows-x64apache-tomcat-9.0.41webappsBlog1_warWEB-INFclassescomjava1234controllerBloggerController.class]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 2 字节的 UTF-8 序列的字节 2 无效。

    <!-- 配置mybatis的sqlSessionFactory -->
      <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
          <property name="dataSource" ref="dataSource" />
          <!-- 自动扫描mappers.xml文件 com.java1234.mappers-->
    <!--       <property name="mapperLocations" value="classpath:com/java1234/mappers/*.xml"/>-->
          <!-- 配置SQL映射文件信息 -->
          <property name="mapperLocations">
              <list>
                  <value>classpath:com/java1234/*/*.xml</value>
              </list>
          </property>
          <!-- mybatis配置文件 -->
          <property name="configLocation" value="classpath:mybatis-config.xml"/>
      </bean>

     

    需求分析

    博客表

    作者表

    博客类别表

    评论表

    友情连接表

     

    tootl

    centos mariadb

     yum install mariadb-server
    # 开启服务
    systemctl start mariadb
    # 设置为开机自启动服务
    systemctl enable mariadb
    mysql_secure_installation
    mysql -u root -p
    /etc/my.cnf 文件
    在 [mysqld] 标签下添加
    init_connect='SET collation_connection = utf8_unicode_ci'
    init_connect='SET NAMES utf8'
    character-set-server=utf8
    collation-server=utf8_unicode_ci
    skip-character-set-client-handshake
    /etc/my.cnf.d/client.cnf 文件

    在 [client] 标签下添加

    default-character-set=utf8
    3)/etc/my.cnf.d/mysql-clients.cnf 文件

    在 [mysql] 标签下添加

    default-character-set=utf8
    4)重启服务

    [root@mini ~]# systemctl restart mariadb
    进入mariadb查看字符集
    show variables like "%character%";show variables like "%collation%";

    远程链接mariadb数据库
    systemctl stop firewalld
    firewall-cmd --zone=public --add-port=3306/tcp --permanent # 开启3306端口
    firewall-cmd --reload
    firewall-cmd --query-port=3306/tcp

    update user set host='%' where host='mini';
    grant all privileges on *.* to 'root'@'%' identified by '1234';
    flush privileges;
    systemctl restart mariadb

     

     

     

    项目整体搭建

    本站源码使用J2EE开发;
    使用Spring5+Springmvc+Mybatis3架构,
    采用Mysql数据库;
    使用Maven3管理项目,使用Shiro作为项目安全框架,使用Lucene作为全文检索,支持restful风格;
    前台网页使用主流的Bootstrap3 UI框架;后台管理使用主流易用的EasyUI轻量级框架;
    数据库连接池使用的是阿里巴巴的Druid;
    在线编辑器使用了百度的UEditor,支持单图,多图上传,支持截图上传,支持代码高亮特性;

     

    WEB-INF

    lib: 导入第三方包,maven找不到的jar包,

     

    web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>aa</display-name>
      <welcome-file-list>
          <welcome-file>a.jsp</welcome-file>
      </welcome-file-list>

      <!-- shiro过滤器定义 -->
      <filter>
          <filter-name>shiroFilter</filter-name>
          <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
          <init-param>
              <!-- 该值缺省为false,表示生命周期由SpringApplicationContext管理,设置为true则表示由ServletContainer管理 -->
              <param-name>targetFilterLifecycle</param-name>
              <param-value>true</param-value>
          </init-param>
      </filter>
    <!--   过滤所有的请求url /* -->
      <filter-mapping>
          <filter-name>shiroFilter</filter-name>
          <url-pattern>/*</url-pattern>
      </filter-mapping>


      <!-- Spring配置文件 -->
      <context-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>classpath:applicationContext.xml</param-value>
      </context-param>
      <!-- 编码过滤器 -->
      <filter>
          <filter-name>encodingFilter</filter-name>
          <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
          <async-supported>true</async-supported>
          <init-param>
              <param-name>encoding</param-name>
              <param-value>UTF-8</param-value>
          </init-param>
      </filter>
      <filter-mapping>
          <filter-name>encodingFilter</filter-name>
          <url-pattern>/*</url-pattern>
      </filter-mapping>
      <!-- Spring监听器 -->
      <listener>
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>

      <listener>
          <listener-class>com.java1234.service.impl.InitComponent</listener-class>
      </listener>

      <!-- 添加对springmvc的支持 -->
      <servlet>
          <servlet-name>springMVC</servlet-name>
          <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
          <init-param>
              <param-name>contextConfigLocation</param-name>
              <param-value>classpath:spring-mvc.xml</param-value>
          </init-param>
          <load-on-startup>1</load-on-startup>
          <async-supported>true</async-supported>
      </servlet>
      <servlet-mapping>
      <!--       后台管理 su优化 -->
          <servlet-name>springMVC</servlet-name>
          <url-pattern>*.do</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
      <!--       伪静态 -->
          <servlet-name>springMVC</servlet-name>
          <url-pattern>*.html</url-pattern>
      </servlet-mapping>

    </web-app>
    因为伪静态 
    <!--映射静态文件: 所有请求static不会被作为action处理 直接作为普通文件-->
      <mvc:resources mapping="/static/**" location="/static/"/>

    包路径搭建

    com.java1234.entity.Blogger

    创建实体类
    idea的generator alt+insert 快捷键生成get/set方法

    创建dao接口:
    com.java1234.dao.BloggerDao
    创建service接口
    com.java1234.service.BloggerService
    com.java1234.service.impl.BloggerServiceImpl
    实现类使用注解:@Service("bloggerService")

    创建controller
    com.java1234.controller.BloggerController
    使用注解
    @Controller
    @RequestMapping("/blogger") url路径

    @Resource //注入
    private BloggerService bloggerService;


    配置文件

    mapper.xml

    com/java1234/mappers/BloggerMapper.xml

    <mapper namespace="com.java1234.dao.BloggerDao">
    <!--结果集映射-->
      <resultMap id="BloggerResult" type="Blogger">
          <result property="id" column="id"/>
          <result property="userName" column="userName"/>
          <result property="password" column="password"/>
      </resultMap>
    <!--   后面会跟着select insert update delete -->
    </mapper>

    applicationContext.xml

    <?xml version="1.0" encoding="UTF-8"?>
      <!-- 配置数据源 -->
      <bean id="dataSource"
            class="com.alibaba.druid.pool.DruidDataSource">
          <property name="url" value="jdbc:mysql://192.168.10.100:3306/db_blog?useUnicode=true&amp;characterEncoding=UTF-8"/>
          <property name="username" value="root"/>
          <property name="password" value="1234"/>
      </bean>

      <!-- 配置mybatis的sqlSessionFactory -->
      <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
          <property name="dataSource" ref="dataSource" />
          <!-- 自动扫描mappers.xml文件 com.java1234.mappers-->
    <!--       <property name="mapperLocations" value="classpath:com/java1234/mappers/*.xml"/> 使用这个property会导致sqlsessionfactory创建失败,导致不能编译,运行-->
          <!-- 配置SQL映射文件信息 -->
          <property name="mapperLocations">
              <list>
                  <value>classpath:com/java1234/*/*.xml</value>
              </list>
          </property>
          <!-- mybatis配置文件 -->
          <property name="configLocation" value="classpath:mybatis-config.xml"/>
      </bean>

      <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
      <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
          <property name="basePackage" value="com.java1234.dao" />
          <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
      </bean>

      <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
      <bean id="transactionManager"
            class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
          <property name="dataSource" ref="dataSource" />
      </bean>

      <!-- 自定义Realm -->
      <bean id="myRealm" class="com.java1234.realm.MyRealm"/>

      <!-- 安全管理器 -->
      <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
          <property name="realm" ref="myRealm"/>
      </bean>

      <!-- Shiro过滤器 -->
      <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
          <!-- Shiro的核心安全接口,这个属性是必须的 -->
          <property name="securityManager" ref="securityManager"/>
          <!-- 身份认证失败,则跳转到登录页面的配置 -->
          <property name="loginUrl" value="/login.jsp"/>
          <!-- Shiro连接约束配置,即过滤链的定义 -->
          <property name="filterChainDefinitions">
              <value>
                  /login=anon
              <!--   进行身份认证 -->
                  /admin/**=authc
              </value>
          </property>
      </bean>

      <!-- 保证实现了Shiro内部lifecycle函数的bean执行 -->
      <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>

      <!-- 开启Shiro注解 -->
      <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor"/>
      <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
          <property name="securityManager" ref="securityManager"/>
      </bean>

      <!-- 配置事务通知属性 -->
      <tx:advice id="txAdvice" transaction-manager="transactionManager">
          <!-- 定义事务传播属性 -->
          <tx:attributes>
              <tx:method name="insert*" propagation="REQUIRED" />
              <tx:method name="update*" propagation="REQUIRED" />
              <tx:method name="edit*" propagation="REQUIRED" />
              <tx:method name="save*" propagation="REQUIRED" />
              <tx:method name="add*" propagation="REQUIRED" />
              <tx:method name="new*" propagation="REQUIRED" />
              <tx:method name="set*" propagation="REQUIRED" />
              <tx:method name="remove*" propagation="REQUIRED" />
              <tx:method name="delete*" propagation="REQUIRED" />
              <tx:method name="change*" propagation="REQUIRED" />
              <tx:method name="check*" propagation="REQUIRED" />
              <tx:method name="get*" propagation="REQUIRED" read-only="true" />
              <tx:method name="find*" propagation="REQUIRED" read-only="true" />
              <tx:method name="load*" propagation="REQUIRED" read-only="true" />
              <tx:method name="*" propagation="REQUIRED" read-only="true" />
          </tx:attributes>
      </tx:advice>

      <!-- 配置事务切面 -->
      <aop:config>
          <aop:pointcut id="serviceOperation"
                        expression="execution(* com.java1234.service.*.*(..))" />
          <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
      </aop:config>

      <!-- 自动扫描 -->
      <context:component-scan base-package="com.java1234.service" />
    </beans>

    log4j.properties

    log4j.rootLogger=DEBUG, Console  

    #Console
    log4j.appender.Console=org.apache.log4j.ConsoleAppender  
    log4j.appender.Console.layout=org.apache.log4j.PatternLayout  
    log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n  

    log4j.logger.java.sql.ResultSet=INFO  
    log4j.logger.org.apache=INFO  
    log4j.logger.java.sql.Connection=DEBUG  
    log4j.logger.java.sql.Statement=DEBUG  
    log4j.logger.java.sql.PreparedStatement=DEBUG  

    mybatis-config.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE configuration
    PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-config.dtd">
    <configuration>
    <!-- 别名 -->
    <typeAliases>
    <package name="com.java1234.entity"/>
    </typeAliases>
    </configuration>

    mapper也可以使用这个配置


    <mappers>
          <mapper resource="cn/dao/WorkinggMapper.xml"/>
    </mappers>

    所以applicationContext.xml这个配置文件就可以不用配置了
    <!-- 配置SQL映射文件信息 -->
    <property name="mapperLocations">
      <list>
      <value>classpath:com/java1234/*/*.xml</value>
      </list>
    </property>

           
    <beans xmlns="http://www.springframework.org/schema/beans"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:p="http://www.springframework.org/schema/p"
          xmlns:aop="http://www.springframework.org/schema/aop"
          xmlns:context="http://www.springframework.org/schema/context"
          xmlns:jee="http://www.springframework.org/schema/jee"
          xmlns:tx="http://www.springframework.org/schema/tx"
          xmlns:mvc="http://www.springframework.org/schema/mvc"
          xsi:schemaLocation="
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
          http://www.springframework.org/schema/mvc   http://www.springframework.org/schema/mvc/spring-mvc.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
          http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">

    spring-mvc.xml

    <?xml version="1.0" encoding="UTF-8"?>


      <mvc:annotation-driven/>
      <!--映射静态文件: 所有请求static不会被作为action处理-->
      <mvc:resources mapping="/static/**" location="/static/"/>

      <!-- 视图解析器 -->
      <bean id="viewResolver"
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
          <property name="prefix" value="/"/>
          <property name="suffix" value=".jsp"></property>
      </bean>
      <!--文件的上传 -->
      <bean id="multipartResolver"
            class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

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

      </bean>

      <!-- 使用注解的包,包括子集 -->
      <context:component-scan base-package="com.java1234.controller"/>
    </beans>

    总结:

    spring-mvc主要是对应关于视图,mvc, c 层,视图层的配置,扫描controller

    mybatis-config.xml 主要是对应dao,entity的配置

    applicationContext.xml service dao shiro tx 事务 aop

     

     

     

     

     

    菜鸟的自白
  • 相关阅读:
    统计学习方法 | 第1章 统计学习方法概论
    统计学习方法 | 第2章 感知机
    LeetCode | DP专题详解
    论文阅读 | Towards a Robust Deep Neural Network in Text Domain A Survey
    DFS(深度优先搜索)和BFS(广度优先搜索)
    Analysis Methods in Neural Language Processing: A Survey
    Spring AMQP 发送消息到 RabbitMQ 收到 x-queue-type 错误
    Gradle 的项目导入到 IntelliJ 后子项目源代码不能导入
    在 CentOS 7 上安装 RabbitMQ
    IntelliJ IDEA 运行项目的时候提示 Command line is too long 错误
  • 原文地址:https://www.cnblogs.com/lzjloveit/p/14165240.html
Copyright © 2020-2023  润新知