7)配置spring相关文件
在META-INF目录下创建目录spring目录
在spring目录下创建文件databaseConfig.properties内容如下
##jdbc.url=jdbc:hsqldb:file:DB/springservice;shutdown=true
jdbc.url=jdbc:sqlserver://localhost:1433;DatabaseName=springrapdemo
jdbc.username=sa
jdbc.password=sa
jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.show_sql=true
#hibernate.hbm2ddl.auto=validate
在spring目录下创建文件applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="META-INF/spring/databaseConfig.properties" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<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>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>com/sword/rapdemo/Employee.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
</props>
</property>
</bean>
<bean id="employeeDao" class="com.sword.rapdemo.EmployeeDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="employeeService" class="com.sword.rapdemo.EmployeeServiceImpl">
<property name="employeeDao" ref="employeeDao" />
</bean>
</beans>
在spring目录下创建文件applicationContext-osgi.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<osgi:service id="employeeServiceOsgi" ref="employeeService" interface="com.sword.rapdemo.EmployeeService"/>
</beans>