Skip to content

Instantly share code, notes, and snippets.

@Matsemann Matsemann/descriptor Secret
Created Mar 12, 2013

Embed
What would you like to do?
<!-- Enable @Controllers with @RequestMapping etc. -->
<mvc:annotation-driven />
<context:component-scan base-package="no.something.project.controller" />
<!-- Enable @Autowired etc. -->
<context:annotation-config />
<!-- Load the db.properties file, can use the values like ${property.name} -->
<context:property-placeholder location="/WEB-INF/db.properties" />
<!-- Enable JPA -->
<jpa:repositories base-package="no.something.project" />
<!-- Connect to DB -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${dataSource.driver}" />
<property name="url" value="${dataSource.url}" />
<property name="username" value="${dataSource.username}" />
<property name="password" value="${dataSource.password}" />
</bean>
<!-- Use the DB inside JPA managers -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="${dataSource.databaseType}" />
<property name="generateDdl" value="true" />
<property name="showSql" value="${dataSource.showSql}" />
</bean>
</property>
<property name="persistenceUnitName" value="jpaPersistenceUnit" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.