「Java開発」Spring MVC構成内容を設定する

1.Spring MVCコード:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task" 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/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.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/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!– 静的リソース要求処理–>
<mvc:resources location="/resources/" mapping="/resources/**" />
<!– すべてのspringコンポーネントをスキャン –>
<context:component-scan base-package="com.startnews24fruit" />
<mvc:annotation-driven></mvc:annotation-driven>
<task:annotation-driven />
<mvc:interceptors>
<bean class="com.startnews24fruit.web.interceptor.PermissionInterceptor"></bean>
</mvc:interceptors>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
<property name="contentType" value="text/html;charset=utf-8″></property>
</bean>

<!– ファイルアップロード処理 –>
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!– one of the properties available; the maximum file size in bytes –>
<property name="maxUploadSize" value="100000000″ />
</bean>
<util:properties id="jdbcProperties" location="classpath:jdbc.properties" />
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="#{jdbcProperties.driverClass}" />
<property name="jdbcUrl" value="#{jdbcProperties.url}" />
<property name="user" value="#{jdbcProperties.username}" />
<property name="password" value="#{jdbcProperties.password}" />
<property name="initialPoolSize" value="3″ />
<property name="minPoolSize" value="1″ />
<property name="maxPoolSize" value="20″ />
<property name="acquireIncrement" value="5″ />
</bean>
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="MYSQL"></property>
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect"></property>
<property name="generateDdl" value="true"></property>
<property name="showSql" value="true"></property>
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="jpaVendorAdapter" ref="jpaVendorAdapter"></property>
</bean>

<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"></bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />

<!– redis spring data –>

<util:properties id="redisprop" location="classpath:redis.properties" />

<bean id="jedisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:hostName="#{redisprop.host}" p:port="#{redisprop.port}" p:usePool="true"
p:password="#{redisprop.passwd}" />

<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"
p:connectionFactory-ref="jedisConnectionFactory" />

</beans>
2.web.xmlを設定
<filter>
<filter-name>encodingFilter</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>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>encodingFilter</filter-name>
<servlet-name>startnews24fruit</servlet-name>
</filter-mapping>
<filter>
<filter-name>htmfilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>htmfilter</filter-name>
<servlet-name>startnews24fruit</servlet-name>
</filter-mapping>
<filter>
<filter-name>initfilter</filter-name>
<filter-class>com.startnews24fruit.web.filter.InitFilter</filter-class>
</filter>
<!– spring DispatcherServlet start –>
<servlet>
<servlet-name>startnews24</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:main.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>startnews24</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

Java

Posted by arkgame