最近闲着无事,写一个Demo(Spring - Hibernate - Maven), 供以后查询。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.hqb.demo</groupId> <artifactId>hibernate</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>hibernate</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>3.5.5.Final</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>4.1.9.Final</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>3.1.4.RELEASE</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.1.4.RELEASE</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>3.1.4.RELEASE</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.0-api</artifactId> <version>1.0.0.Final</version> </dependency> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.2.2</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>3.0.5.RELEASE</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>3.5.5-Final</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-annotations</artifactId> <version>3.5.5-Final</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.5.8</version> </dependency> <dependency> <groupId>com.oracle</groupId> <artifactId>oracle-jdbc</artifactId> <version>10.2.0.4.0</version> </dependency> </dependencies> </project>
<?xml version="1.0" encoding="UTF-8"?> <settings> <localRepository>P:/Steven/DEV/maven_repo</localRepository> <proxies> </proxies> <servers> </servers> <mirrors> <mirror> <id>ssts mr</id> <name>Internal Mirror of Central Repository</name> <url>http://xxxxxxxxxxxxxxxxx.com:8080/archiva/repository/internal</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors> <profiles> <profile> <id>default</id> <activation> <activeByDefault>true</activeByDefault> </activation> <repositories> <repository> <id>ssts</id> <name>Internal Mirror of Central Repository</name> <releases> <enabled>true</enabled> <updatePolicy>never</updatePolicy> <checksumPolicy>ignore</checksumPolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>never</updatePolicy> <checksumPolicy>ignore</checksumPolicy> </snapshots> <url>http://xxxxxxxxxxxxxxxxx.com:8080/archiva/repository/internal</url> </repository> <repository> <id>ssts-fusa</id> <name>Internal Mirror of Central Repository</name> <releases> <enabled>true</enabled> <updatePolicy>never</updatePolicy> <checksumPolicy>ignore</checksumPolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>never</updatePolicy> <checksumPolicy>ignore</checksumPolicy> </snapshots> <url>http://xxxxxxx-build:9090/maven-repo/</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>ssts</id> <name>Internal Mirror of Central Plugins Repository</name> <releases> <enabled>true</enabled> <updatePolicy>never</updatePolicy> <checksumPolicy>ignore</checksumPolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>never</updatePolicy> <checksumPolicy>ignore</checksumPolicy> </snapshots> <url>http://xxxxxxxxxx.com:8080/archiva/repository/internal</url> </pluginRepository> </pluginRepositories> </profile> </profiles> </settings>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd "> <context:property-placeholder location="classpath*:*.properties" /> <bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="url" value="${db.url}" /> <property name="username" value="${db.username}" /> <property name="password" value="${db.password}" /> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="datasource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop> <prop key="hibernate.show_sql">false</prop> <prop key="hibernate.format_sql">false</prop> </props> </property> <property name="packagesToScan" value="com.hqb.demo.entity" /> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> <bean id="studentDao" class="com.hqb.demo.dao.impl.StudentDaoImpl"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="studentService" class="com.hqb.demo.service.impl.StudentServiceImpl"> <property name="studentDao" ref="studentDao" /> </bean> <bean id="controller" class="com.hqb.demo.DemoController"> <property name="studentService" ref="studentService" /> </bean> </beans>