1
2
3
4
5
6
|
<
bean
id
=
"myDataSource"
class
=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method
=
"close"
>
<
property
name
=
"driverClassName"
value
=
"com.mysql.jdbc.Driver"
/>
<
property
name
=
"url"
value
=
"jdbc:mysql://localhost:3306/mydb"
/>
<
property
name
=
"username"
value
=
"root"
/>
<
property
name
=
"password"
value
=
"3423"
/>
</
bean
>
|
1
2
3
4
5
6
7
8
9
10
|
<
bean
class
=
"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
>
<
property
name
=
"locations"
value
=
"classpath:com/foo/jdbc.properties"
/>
</
bean
>
<
bean
id
=
"dataSource"
destroy-method
=
"close"
class
=
"org.apache.commons.dbcp.BasicDataSource"
>
<
property
name
=
"driverClassName"
value
=
"${jdbc.driverClassName}"
/>
<
property
name
=
"url"
value
=
"${jdbc.url}"
/>
<
property
name
=
"username"
value
=
"${jdbc.username}"
/>
<
property
name
=
"password"
value
=
"${jdbc.password}"
/>
</
bean
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
<
bean
id
=
"sessionFatory"
class
=
"org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
>
<
property
name
=
"dataSource"
ref
=
"dataSource"
/>
<!—当用annotation注解实体的时候,class必须为 *.hibernate3.annotation.AnnotationSessionFactoryBean -->
<
property
name
=
"annotatedClasses"
>
<
list
>
<
value
>com.bjsxt.model.User</
value
>
<
value
>com.bjsxt.model.Manager</
value
>
</
list
>
</
property
>
还有一种方法,这仅仅用于annotation中,扫描注定包中的实体类
<
property
name
=
"packagesToScan"
>
<
list
>
<
value
>com.bjsxt.model</
value
>
</
list
>
</
property
>
<!—当用hbm.xml的时候,class必须为*.hibernate3.LocalSessionFactoryBean -->
<
property
name
=
"mappingResources"
>
<
list
>
<
value
>product.hbm.xml</
value
>
</
list
>
</
property
>
<!—第一种指定值-->
<
property
name
=
"hibernateProperties"
>
<
props
>
<
prop
key
=
"hibernate.dialect"
>
org.hibernate.dialect.MySQLDialect</
prop
>
<
prop
key
=
"hibernate.show_sql"
>true</
prop
>
<
prop
key
=
"hibernate.format_sql"
>true</
prop
>
<
prop
key
=
"hibernate.hbm2ddl.auto"
>update</
prop
>
</
props
>
</
property
>
<!—第二种指定值-->
<
property
name
=
"hibernateProperties"
>
<
value
>
hibernate.dialect=org.hibernate.dialect.HSQLDialect
</
value
>
<
value
>hibernate.show_sql=true</
value
>
</
property
>
</
bean
>
|
1
2
3
|
<
bean
id
=
"hibernateTemplate"
class
=
"org.springframework.orm.hibernate3.HibernateTemplate"
>
<
property
name
=
"sessionFactory"
ref
=
"sessionFactory"
></
property
>
</
bean
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
web-app
id
=
"WebApp_9"
version
=
"2.4"
xmlns
=
"http://java.sun.com/xml/ns/j2ee"
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!—设置监听器,使得应用程序启动就开始创建我们的beans-->
<
listener
>
<
listener-class
>org.springframework.web.context.ContextLoaderListener</
listener-class
>
</
listener
>
<!—配置应用程序加载的beans的路径-->
<
context-param
>
<
param-name
>contextConfigLocation</
param-name
>
<
param-value
>/WEB-INF/applicationContext-*.xml,classpath*:
applicationContext-*.xml</
param-value
>
</
context-param
>
<!—struts基本配置,主要是负责过滤url请求的-->
<
display-name
>Struts Blank</
display-name
>
<
filter
>
<
filter-name
>struts2</
filter-name
>
<
filter-class
>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</
filter-class
>
</
filter
>
<
filter-mapping
>
<
filter-name
>struts2</
filter-name
>
<
url-pattern
>/*</
url-pattern
>
</
filter-mapping
>
<
welcome-file-list
>
<
welcome-file
>index.html</
welcome-file
>
</
welcome-file-list
>
</
web-app
>
|
1
2
3
4
5
6
7
8
9
|
<
filter
>
<
filter-name
>openSessionInView</
filter-name
>
<
filter-class
>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</
filter-class
>
</
filter
>
<
filter-mapping
>
<
filter-name
>openSessionInView</
filter-name
>
<
url-pattern
>/*</
url-pattern
>
</
filter-mapping
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<
filter
>
<
filter-name
>encodingFilter</
filter-name
>
<
filter-class
>
org.springframework.web.filter.CharacterEncodingFilter</
filter-class
>
<
init-param
>
<
param-name
>encoding</
param-name
>
<
param-value
>GBK</
param-value
>
</
init-param
>
</
filter
>
<
filter-mapping
>
<
filter-name
>encodingFilter</
filter-name
>
<
url-pattern
>/*</
url-pattern
>
</
filter-mapping
>
|