SSH整合学习知识点(二)

1.Spring配置文件applicationContext.xml中的数据源配置代码如下,其中数据源采用apache的实现类org.apache.commons.dbcp.BasicDataSource来注入进去,该类位于commons-dbcp.jar包中。

 

 

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">

<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>

<property name="url" value="jdbc:mysql://localhost:3306/mytest"></property>

<property name="username" value="root"></property>

<property name="password" value="wang"></property>

<property name="maxActive" value="100"></property>---连接池最大连接数

<property name="maxIdle" value="30"></property>---连接池最大空闲连接数

<property name="maxWait" value="500"></property>---连接池最大等待连接数

<property name="defaultAutoCommit" value="true"></property>

</bean>---是否允许事务自动提交

 

 

根据Spring最佳实践,对无状态的bean一般配置成单例的singleton(如dao),而对有状态的bean一般配置成原型类型的prototype,spring默认的规则就是单例的。此处的单例同设计模式的单例不同,对于设计模式的单例是指整个jvm运行中指产生一个实例对象,spring中的单例是指在每一个spring IOC容易中存在一个实例对象。

 

2.struts2里的action实例对象都是由spring帮助创建的,struts2在启动时会依次加载3个xml文件:struts-default.xml,struts-plugin.xml,struts.xml。

 

<!--EndFragment-->

你可能感兴趣的:(spring,mysql,bean,struts,ssh)