编程 54

SSH的Eclips情形搭建

By admin in 编程 on 2019年5月21日

報錯:

一.开立数据库名称叫:dungouoa

myeclipse7.0 配置SSH问题?
myeclipse7.0 配置SSH问题:

org.springframework.beans.factory.BeanDefinitionStoreException:
Unexpected exception parsing XML document from class path resource
[beans.xml]; nested exception is java.lang.IllegalStateException:
Context namespace element ‘annotation-config’ and its parser class
[org.springframework.context.annotation.AnnotationConfigBeanDefinitionParser
are only available on JDK 1.5 and higher

create database dungouoa default character set utf8;
mysql> show create database dungouoa;
+———-+——————————————————————-+
| Database | Create Database |
+———-+——————————————————————-+
| dungouoa | CREATE DATABASE `dungouoa` /*!40100 DEFAULT CHARACTER
SET utf8 */ |
+———-+——————————————————————-+

在配置SPLANDING的配备文件时,用mappingLocations写
/*在调整台加载测试时会报找不到文件,而且把*调换文件名,就可以了,请问这是怎么啊?有知情的么?大哥是新手。

编程 1

二.创建eclips的工程
@一创建web工程,编码设为utf-八

以下那样就不报错:

忽略:SPTiguanING的注明配置分析器只可以在JDK1.五或更加高版本选用,笔者的ECLIPSE
暗许的是一.八,笔者利用的SPBMWX3ING版本是②.伍,总来说之便是一.八的JDK太高了,SPCR-VING
支持不住。

编程 2

classpath:config/hbm/TbPerson.hbm.xml

前提是:你在Spring容器里面配备了,annotation-driven来启用事务

编程 3

[color=red][color=red]报错:

<!-- 配置事务管理器,统一管理session Factory的事务 -->
    <bean id="txManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    <!-- 启用事务注解 -->
    <tx:annotation-driven
        transaction-manager="txManager" />

 

classpath:config/hbm/*

解决:项目右键–》BUILD PATH–》Config Build Path–》Libraries–>Jre
System Library–》艾德it–》配置一.柒的就OK 啦!

@贰增多框架情形
Junit

[/color][/color]

编程 4

编程 5

spring2.0+hibernate3.1
[b]难点补充:[/b]

 

 

classpath:config/hbm/*hbm.xml

 

本来也加过了。。也十分。。不知晓干什么。。何人遇到那样的标题吧。。
[b]主题素材补充:[/b]

@1Structs2

  • Pre-instantiating singletons in
    org.springframework.beans.factory.support.DefaultListableBeanFactory@30d82d:
    defining beans
    [dataSource,sessionFactory,personDaoImpl,personServImpl,/login];
    root of factory hierarchy
  • Hibernate 3.1.3
  • hibernate.properties not found
  • using CGLIB reflection optimizer
  • using JDK 1.4 java.sql.Timestamp handlingException in thread “main”
    org.springframework.beans.factory.BeanCreationException:

添加jar包,

[color=red]Error creating bean with name ‘sessionFactory’ defined in
class path resource [config/spring/applicationContext.xml]: Invocation
of init method failed; nested exception is
java.io.FileNotFoundException: class path resource
[config/hbm/**.hbm.xml] cannot be opened because it does not exist
Caused by: java.io.FileNotFoundException: class path resource
[config/hbm/**.hbm.xml] cannot be opened because it does not exist
at
org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:135)
at
org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:656)
at
org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1203)[/color]-

编程 6

报这几个错。是还是不是MYECLIPSE7.0失常呀。在伍.五上就不报错。没事。而且TOMCAT运营也不报错

 

编程 7

 

 编程 8

 

修改structs.xml,

编程 9

编程 10

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <!-- 配置为开发模式-->
    <constant name="struts.devMode" value="true" />
    <!--把扩展名配置为action  -->
    <constant name="struts.action.extension" value="action" />
    <!--把主题配置为simple  -->
    <constant name="struts.ui.theme" value="simple" />




    <package name="default" namespace="/" extends="struts-default">


    </package>

    <!-- Add packages here -->

</struts>

 

 

 web.xml的structs二过滤器拷贝到工程的web.xml中

编程 11

编程 12

 

 编程 13

 

@2Spring

jar包

编程 14

编程 15

编程 16

编程 17

 

 

 

applicationContext.xml  / bean.xml

编程 18

<?xml version="1.0" encoding="UTF-8"?>
<!--
  - Middle tier application context definition for the image database.
  -->
<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:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
        <!--自动扫描预装配bean  -->

        <context:component-scan base-package="cn.hui.oa"></context:component-scan>


</beans>

 

 

 

@3Hibernate

 

jar包,

编程 19

编程 20

编程 21

编程 22

主配置文件,映射文件

 

 

 

编程 23

编程 24

<?xml version='1.0' encoding='utf-8'?>
<!--
  ~ Hibernate, Relational Persistence for Idiomatic Java
  ~
  ~ Copyright (c) 2010, Red Hat Inc. or third-party contributors as
  ~ indicated by the @author tags or express copyright attribution
  ~ statements applied by the authors.  All third-party contributions are
  ~ distributed under license by Red Hat Inc.
  ~
  ~ This copyrighted material is made available to anyone wishing to use, modify,
  ~ copy, or redistribute it subject to the terms and conditions of the GNU
  ~ Lesser General Public License, as published by the Free Software Foundation.
  ~
  ~ This program is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  ~ or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
  ~ for more details.
  ~
  ~ You should have received a copy of the GNU Lesser General Public License
  ~ along with this distribution; if not, write to:
  ~ Free Software Foundation, Inc.
  ~ 51 Franklin Street, Fifth Floor
  ~ Boston, MA  02110-1301  USA
  -->
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>

        <!-- 1.数据库连接信息 -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <!--配置数据库的url位本地的名称为 testjdbc的数据库 -->
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/dungouoa</property>
        <!--配置用户名  -->
        <property name="hibernate.connection.username">root</property>

        <!--配置密码  -->
        <property name="hibernate.connection.password">241602</property>
        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>
        <!-- SQL dialect mysql方言-->
        <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- 其他配置 -->
        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

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

        <!-- 导入映射文件 -->
        <mapping resource="org/hibernate/tutorial/hbm/Event.hbm.xml"/>

    </session-factory>

</hibernate-configuration>

 

@3整合SSH
——Structs2和Spring整合

——-整合此前Structs2测试,增加action

编程 25

action类

编程 26

jsp页

编程 27

编程 28

测试的运作结果

 编程 29

网页展现

编程 30

——-Spring整合在此之前测试

——-测试类

编程 31

——证明bean对象,使用注明,多种方法

编程 32

配备bean的功用域,多例,不写Scope为单例

编程 33

 

 不应用注明的话则在xml文件重配置注解bean

编程 34

测试后报错如下:

java.lang.ExceptionInInitializerError
Caused by:
org.springframework.beans.factory.BeanDefinitionStoreException:
Unexpected exception parsing XML document from class path resource
[beans.xml]; nested exception is java.lang.IllegalStateException:
Context namespace element ‘component-scan’ and its parser class
[org.springframework.context.annotation.ComponentScanBeanDefinitionParser]
are only available on JDK 1.5 and higher

经查阅后是Spring和JDK版本包容难点,后来自家把富有前边导入的与spring有关jar包都剔除,换到下边三.贰.玖的jar包后打响了

编程 35

 

 单独spring测试结果

编程 36

——Structs二和Spring整合测试

——-一.在web.xml中布署SP大切诺基ING用于容器对象开始化的监听器

 编程 37

编程 38

——二.增加3个插件和四个jar包

 编程 39

 

 编程 40

 

structs.xml文件

 编程 41

 结果展现:

编程 42

 

 

Hibernate和Spring整合

目的:

@壹管理SessionFactory对象,3个实例

@2声称事务管理

添加jar包

编程 43

编程 44

 

 applicationContext.xml中布局出席如下

    <!-- 配置SessionFactory对象 -->
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <!-- 指定配置文件路径 -->
        <property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
        <!-- 配置c3p0数据库连接池 -->
        <property name="dataSource">
            <bean class="com.mchange.v2.c3p0.ComboPooledDataSource">
                <!-- 数据连接信息 -->
                <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
                <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/dungouoa"></property>
                <property name="user" value="root"></property>
                <property name="password" value="241602"></property>

                <!--其他配置  -->
                <!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
                <property name="initialPoolSize" value="3"></property>
                <!--连接池中保留的最小连接数。Default: 3 -->
                <property name="minPoolSize" value="3"></property>
                <!--连接池中保留的最大连接数。Default: 15 -->
                <property name="maxPoolSize" value="5"></property>
                <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
                <property name="acquireIncrement" value="3"></property>
                <!-- 控制数据源内加载的PreparedStatements数量。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 -->
                <property name="maxStatements" value="8"></property>
                <!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 -->
                <property name="maxStatementsPerConnection" value="5"></property>
                <!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
                <property name="maxIdleTime" value="1800"></property>


            </bean>


        </property>
    </bean>

 

 

 运营后报错:

org.springframework.beans.factory.CannotLoadBeanClassException: Error
loading class [org.springframe

导入如下jar包就能够

编程 45

运行结果:

编程 46

 

Spring

IOC:管理对象

AOP:事务管理

编程,—-注脚事务管理

编程 47

 

编程 48

编程 49

编程 50

编程 51

 

编程 52

 

 

运行报错:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed
to read candidate component c

编写翻译器的JDK1.捌改为1.7就可以缓解

JUnit测试运转结果:

编程 53

 

编程 54

 

 

 

 

 

 

 

@四能源分类
@伍配置日志

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图
Copyright @ 2010-2020 澳门新葡亰官网app 版权所有