SpringMVC Hibernate 주석 기반 설정
SpringMVC 에 대해 서 는 잠시 후에 필 기 를 하 겠 습 니 다.
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!-- POST -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>chapter2</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>chapter2</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
주석 기반 설정 chapter 2 - servlet. 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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
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-2.5.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:component-scan base-package="chapter2" ></context:component-scan>
<!-- -->
<mvc:resources location="/resources/" mapping="/resources/**"/>
<!-- ,
-->
<mvc:default-servlet-handler />
<!-- Spring Ioc -->
<context:annotation-config />
<!-- HandlerMapping HandlerAdapter bean -->
<mvc:annotation-driven />
<!-- SpringMVC
<bean
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />
<bean
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" />
-->
<!-- “/” , “/helloworld/index” -->
<!--
<mvc:view-controller path="/" view-name="forward:/hello" />
-->
<!-- @Transactional
<tx:annotation-driven proxy-target-class="true" transaction-manager="txManager" />
-->
<!-- -->
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="merge*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
<tx:method name="put*" propagation="REQUIRED" />
<tx:method name="get*" propagation="SUPPORTS"
read-only="true" />
<tx:method name="count*" propagation="SUPPORTS"
read-only="true" />
<tx:method name="find*" propagation="SUPPORTS"
read-only="true" />
<tx:method name="list*" propagation="SUPPORTS"
read-only="true" />
<tx:method name="*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="interceptorPointCuts"
expression="execution(* com.ycj..*.*(..))" /><!-- ycj -->
<aop:advisor advice-ref="txAdvice"
pointcut-ref="interceptorPointCuts" />
</aop:config>
<!-- resources bean.xml -->
<import resource="classpath: **/spring-*.xml" />
<bean id="jdbcProperties"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:my.properties"></property>
</bean>
<!-- URL -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<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" /><!-- -->
<!-- hibernate -->
<!-- ①mappingResources classpath xxx.hbm.xml -->
<!-- ②mappingLocations and classpath: /com/xxx/*.hbm.xml -->
<!-- ③mappingDirectoryLocations WEB-INF/HibernateMapping or classpath:/XXX/package -->
<!-- ④mappingJarLocations jar -->
<property name="mappingDirectoryLocations">
<list>
<value></value><!-- hibernate *.hbm.xml -->
</list>
</property>
<property name="hibernateProperties">
<props>
<!-- hibernate -->
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop><!-- sql -->
<!--<prop key="hibernate.current_session_context_class">thread</prop>-->
</props>
</property>
</bean>
<!-- ViewResolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
주석 기반 설정 chapter 2 - servlet. 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.xsd">
<bean id="jdbcProperties"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:my.properties"></property>
</bean>
<!-- URL -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<!--
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/demo" />
<property name="username" value="root" />
<property name="password" value="root" />
-->
<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" /><!-- -->
<!-- hibernate -->
<!-- ①mappingResources classpath xxx.hbm.xml -->
<!-- ②mappingLocations and classpath: /com/xxx/*.hbm.xml -->
<!-- ③mappingDirectoryLocations WEB-INF/HibernateMapping or classpath:/XXX/package -->
<!-- ④mappingJarLocations jar -->
<property name="mappingDirectoryLocations">
<list>
<value></value><!-- hibernate *.hbm.xml -->
</list>
</property>
<property name="hibernateProperties">
<props>
<!-- hibernate -->
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<!--<prop key="hibernate.current_session_context_class">thread</prop>-->
</props>
<!--
<props>
// oracle , SQL
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
// HQL
<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>
// sql
<prop key="hibernate.show_sql">true </prop>
// Hibernate hibernate.use_outer_join , outer join 。
<prop key="hibernate.use_outer_join">true </prop>
// , cglib 。cglib Hibernate PO ,
<prop key="hibernate.cglib.use_reflection_optimizer">true </prop>
// sql,
<prop key="hibernate.format_sql">true </prop>
//“useUnicode” “characterEncoding” Encode, Encode
<prop key="hibernate.connection.useUnicode">true </prop>
// , .
<prop key="hibernate.cache.use_query_cache">false </prop>
<prop key="hibernate.default_batch_fetch_size">16 </prop>
//
<prop key="hibernate.dbcp.maxActive">100 </prop>
// ,DBCP (0 = ,1 = ,2 = )
<prop key="hibernate.dbcp.whenExhaustedAction">1 </prop>
//
<prop key="hibernate.dbcp.maxWait">1200 </prop>
// ,
<prop key="hibernate.dbcp.maxIdle">10 </prop>
## prepared statement , 。
<prop key="hibernate.dbcp.ps.maxActive">100 </prop>
<prop key="hibernate.dbcp.ps.whenExhaustedAction">1 </prop>
<prop key="hibernate.dbcp.ps.maxWait">1200 </prop>
<prop key="hibernate.dbcp.ps.maxIdle">10 </prop>
</props>
-->
</property>
</bean>
<!-- HandlerMapping -->
<!-- URL Bean
URL " /hello", Spring "/hello" bean-->
<bean
class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
<!-- HandlerAdapter -->
<!-- org.springframework.web.servlet.mvc.Controller
Bean Spring MVC -->
<bean
class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
<!-- ViewResolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- -->
<bean name="/hello"
class="cn.javass.chapter2.web.controller.HelloWorldController" />
<bean name="/login"
class="cn.javass.chapter2.web.controller.LoginController">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.