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
|
xml
version
=
"1.0"
encoding
=
"utf8"
?>
<
beans
xmlns
=
"http://www.springframework.org/schema/beans"
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop
=
"http://www.springframework.org/schema/aop"
xmlns:tx
=
"http://www.springframework.org/schema/tx"
xmlns:context
=
"http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
default-autowire
=
"byName"
default-lazy-init
=
"false"
>
<
bean
id
=
"dataSource"
class
=
"org.apache.commons.dbcp.BasicDataSource"
>
<
property
name
=
"driverClassName"
value
=
"com.mysql.jdbc.Driver"
/>
<
property
name
=
"url"
value
=
"jdbc:mysql://localhost/courseman"
/>
<
property
name
=
"username"
value
=
"courseman"
/>
<
property
name
=
"password"
value
=
"abc123"
/>
bean
>
<
bean
id
=
"sqlSessionFactory"
class
=
"org.mybatis.spring.SqlSessionFactoryBean"
>
<
property
name
=
"dataSource"
ref
=
"dataSource"
/>
<
property
name
=
"configLocation"
value
=
"resources/configuration.xml"
/>
bean
>
<
bean
class
=
"org.mybatis.spring.mapper.MapperScannerConfigurer"
>
<
property
name
=
"basePackage"
value
=
"com.abc.mapper"
/>
bean
>
beans
>
|
1
|
TeacherMapper mapper = (TeacherMapper)ctx.getBean(
"teacherMapper"
);
|
1
2
3
4
5
6
7
|
package
com.abc.mapper;
import
com.abc.domain.Teacher;
import
org.springframework.stereotype.Component;
@Component
(
"myTeacherMapper"
)
public
interface
TeacherMapper {
public
Teacher getById(
int
id);
}
|
1
|
TeacherMapper mapper = (TeacherMapper)ctx.getBean(
"myTeacherMapper"
);
|