persistence work

This commit is contained in:
eugenp 2013-05-04 22:44:39 +03:00
parent debee3bf5c
commit 015050f928
3 changed files with 143 additions and 129 deletions

View File

@ -11,6 +11,11 @@
<!-- Spring --> <!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId> <artifactId>spring-orm</artifactId>
@ -35,6 +40,13 @@
<version>4.2.1.Final</version> <version>4.2.1.Final</version>
</dependency> </dependency>
<!-- utils -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>14.0.1</version>
</dependency>
<!-- test scoped --> <!-- test scoped -->

View File

@ -15,6 +15,8 @@ import org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBea
import org.springframework.orm.hibernate4.HibernateTransactionManager; import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import com.google.common.base.Preconditions;
@Configuration @Configuration
@EnableTransactionManagement @EnableTransactionManagement
@ComponentScan({ "org.baeldung.spring.persistence.dao", "org.baeldung.spring.persistence.service" }) @ComponentScan({ "org.baeldung.spring.persistence.dao", "org.baeldung.spring.persistence.service" })
@ -40,10 +42,10 @@ public class PersistenceConfig {
@Bean @Bean
public DataSource restDataSource() { public DataSource restDataSource() {
final DriverManagerDataSource dataSource = new DriverManagerDataSource(); final DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName")); dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName")));
dataSource.setUrl(env.getProperty("jdbc.url")); dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url")));
dataSource.setUsername(env.getProperty("jdbc.user")); dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user")));
dataSource.setPassword(env.getProperty("jdbc.pass")); dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass")));
return dataSource; return dataSource;
} }

View File

@ -22,19 +22,19 @@
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> </listener>
<!-- Spring child --> <!-- Spring web -->
<servlet> <!-- <servlet> -->
<servlet-name>mvc</servlet-name> <!-- <servlet-name>mvc</servlet-name> -->
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> -->
<load-on-startup>1</load-on-startup> <!-- <load-on-startup>1</load-on-startup> -->
</servlet> <!-- </servlet> -->
<servlet-mapping> <!-- <servlet-mapping> -->
<servlet-name>mvc</servlet-name> <!-- <servlet-name>mvc</servlet-name> -->
<url-pattern>/</url-pattern> <!-- <url-pattern>/</url-pattern> -->
</servlet-mapping> <!-- </servlet-mapping> -->
<welcome-file-list> <!-- <welcome-file-list> -->
<welcome-file>index.html</welcome-file> <!-- <welcome-file>index.html</welcome-file> -->
</welcome-file-list> <!-- </welcome-file-list> -->
</web-app> </web-app>