Spring-dispatcher-servlet.xml to Java Config -
hi i'm trying convert xml configuration java config. i'm lost now.
here spring-dispatcher-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!-- package of spring controller --> <context:component-scan base-package="com.test" /> <mvc:annotation-driven /> <bean class="org.springframework.web.servlet.mvc.annotation.annotationmethodhandleradapter"> <property name="cacheseconds" value="0" /> </bean> <mvc:resources mapping="/resources/**" location="/resources/" cache-period="31556926" /> <bean id="viewresolver1" class="org.springframework.web.servlet.view.xmlviewresolver"> <property name="location" value="/web-inf/excel-view.xml" /> </bean> <bean id="viewresolver2" class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix"> <value>/web-inf/jsp/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> <bean id="multipartresolver" class="org.springframework.web.multipart.commons.commonsmultipartresolver"> <!-- setting maximum upload size --> <property name="maxuploadsize" value="100000" /> </bean> <!-- read test.properties --> <bean class="org.springframework.beans.factory.config.propertyplaceholderconfigurer"> <property name="location"> <value>classpath:test.properties</value> </property> </bean> <bean id="entitymanagerfactorybean" class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean"> <property name="datasource" ref="datasource" /> <!-- makes /meta-inf/persistence.xml no longer necessary --> <property name="packagestoscan" value="com.beo.model" /> <!-- jpavendoradapter implementation hibernate entitymanager. exposes hibernate's persistence provider , entitymanager extension interface --> <property name="jpavendoradapter"> <bean class="org.springframework.orm.jpa.vendor.hibernatejpavendoradapter" /> </property> <property name="jpaproperties"> <props> <!-- <prop key="hibernate.hbm2ddl.auto">create</prop> --> <!-- <prop key="hibernate.show_sql">true</prop> --> <prop key="hibernate.dialect">org.hibernate.dialect.postgresqldialect</prop> </props> </property> </bean> <bean id="datasource" class="com.zaxxer.hikari.hikaridatasource"> <!-- hikari config --> <property name="datasourceclassname" value="${hikari.datasourceclassname}" /> <property name="maximumpoolsize" value="${hikari.maximumpoolsize}" /> <property name="maxlifetime" value="${hikari.maxlifetime}" /> <property name="idletimeout" value="${hikari.idletimeout}" /> <property name="datasourceproperties"> <props> <prop key="url">${jdbc.url}</prop> <prop key="user">${jdbc.username}</prop> <prop key="password">${jdbc.password}</prop> </props> </property> </bean> <!-- transaction manager appropriate applications use single jpa entitymanagerfactory transactional data access. jta (usually through jtatransactionmanager) necessary accessing multiple transactional resources within same transaction. --> <bean id="transactionmanager" class="org.springframework.orm.jpa.jpatransactionmanager"> <property name="entitymanagerfactory" ref="entitymanagerfactorybean" /> </bean> <!-- responsible registering necessary spring components power annotation-driven transaction management; such when @transactional methods invoked --> <tx:annotation-driven /> </beans>
here came java config.
@configuration @enablewebmvc @componentscan("com.test") public class webconfig extends webmvcconfigureradapter { @override public void addresourcehandlers(final resourcehandlerregistry registry) { registry.addresourcehandler("/resources/**") .addresourcelocations("/resources/").setcacheperiod(31556926); } @override public void configuredefaultservlethandling( defaultservlethandlerconfigurer configurer) { configurer.enable(); } @bean public viewresolver setupviewresolver(contentnegotiationmanager manager) { list<viewresolver> resolvers = new arraylist<viewresolver>(); internalresourceviewresolver internalresourceresolver = new internalresourceviewresolver(); internalresourceresolver.setprefix("/web-inf/jsp/"); internalresourceresolver.setsuffix(".jsp"); resolvers.add(internalresourceresolver); contentnegotiatingviewresolver resolver2 = new contentnegotiatingviewresolver(); resolver2.setviewresolvers(resolvers); resolver2.setcontentnegotiationmanager(manager); return resolver2; } }
thank in advance help.
Comments
Post a Comment