springMVC3+apache CXF+spring security3+mybatis3(proxool)整合项目

整合出现很多问题,这里就不例举了,大家各自修炼吧,这里我只提供demo架包,可以在里面折腾。这里我说一下为什么会有这样的框架:我们项目要求是为子系统提供权限认证和管理(web service),同时对这些web service进行权限管理。所以demo中对security做了url和方法级的认证做了扩展,但没做具体实现。

1.web.xml

<?xml version="1.0" encoding="UTF-8" ?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <display-name>Archetype Created Web Application</display-name>
   <servlet>
        <servlet-name>CXFServlet</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
		<load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/ws/*</url-pattern>
    </servlet-mapping>
    <context-param>
         <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/*.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>
            org.springframework.web.filter.DelegatingFilterProxy
        </filter-class>
   </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
<servlet>
		<servlet-name>spring</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>spring</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>

	<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.png</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.gif</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.ico</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.gif</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
	<error-page>
<exception-type>500</exception-type>
<location>/500.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/404.jsp</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>/403.jsp</location>
</error-page>
</web-app>

2.spring.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:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
	xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:security="http://www.springframework.org/schema/security" xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
	http://www.springframework.org/schema/security
	http://www.springframework.org/schema/security/spring-security-3.2.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.2.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">

	<context:component-scan base-package="clubgod.controller" />
		<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver"
		p:prefix="/WEB-INF/view/" p:suffix=".jsp" />
		 <!-- 支持文件上传 -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="defaultEncoding" value="UTF-8" />
        <!-- <property name="maxUploadSize" value="5000000" />  max size 5M -->
    </bean>
	<bean
		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="messageConverters">
			<list>
				<bean
					class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
			</list>
		</property>
	</bean>
</beans>

3.applicationContext.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:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
	xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:security="http://www.springframework.org/schema/security"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
	http://www.springframework.org/schema/security
	http://www.springframework.org/schema/security/spring-security-3.2.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.2.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">

	<security:global-method-security access-decision-manager-ref="clubgodAccessDecisionManager">
		<security:protect-pointcut access="none" expression="execution(* clubgod.service.I*.*(..))"/>
	</security:global-method-security>

	<security:http pattern="/login" security="none" />
	<security:http pattern="/" security="none" />
	<security:http pattern="/ws/**" security="none" />
	<security:http pattern="/favicon.ico" security="none" />
	<security:http pattern="/*.jsp" security="none" />
	<security:http pattern="/resource/**" security="none" />
	<security:http  use-expressions="true"
		access-denied-page="/403.jsp" entry-point-ref="authenticationProcessingFilterEntryPoint">
        <security:logout/>
        <!-- 实现免登陆验证 -->
        <security:remember-me />
        <security:session-management invalid-session-url="/">
            <security:concurrency-control max-sessions="10" error-if-maximum-exceeded="true" />
        </security:session-management>
       	<security:custom-filter ref="clubgodLoginAuthenticationFilter" position="FORM_LOGIN_FILTER"  />
		<security:custom-filter ref="clubgodSecurityFilter"	before="FILTER_SECURITY_INTERCEPTOR" />
	</security:http>
	<bean id="clubgodSecurityFilter"  class="clubgod.security.common.ClubgodSecurityFilter">
		<property name="authenticationManager" ref="clubgodAuthenticationManager" />
		<property name="accessDecisionManager" ref="clubgodAccessDecisionManager" />
		<property name="securityMetadataSource" ref="clubgodMetadataSourceService" />
	</bean>
	<security:authentication-manager alias="clubgodAuthenticationManager">
	<security:authentication-provider user-service-ref="securityUserDetailsService"/>
	</security:authentication-manager>
	<bean id="clubgodAccessDecisionManager"  class="clubgod.security.common.ClubgodAccessDecisionManager">
	</bean>

	<bean id="clubgodMetadataSourceService"  class="clubgod.security.common.ClubgodMetadataSourceService">
	</bean>
	<bean id="securityUserDetailsService"  class="clubgod.security.common.SecurityUserDetailsService">
	</bean>
	 <!-- 登录验证器 -->
    <bean id="clubgodLoginAuthenticationFilter"	class="clubgod.security.common.ClubgodLoginAuthenticationFilter">
		<!-- 处理登录 -->
		<property name="filterProcessesUrl" value="/j_spring_security_check"></property>
		<property name="authenticationSuccessHandler" ref="loginLogAuthenticationSuccessHandler"></property>
		<property name="authenticationFailureHandler" ref="simpleUrlAuthenticationFailureHandler"></property>
		<property name="authenticationManager" ref="clubgodAuthenticationManager"></property>

	</bean>
	<bean id="loginLogAuthenticationSuccessHandler"
		class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">
		<property name="defaultTargetUrl" value="/home"></property>
	</bean>
	<bean id="simpleUrlAuthenticationFailureHandler"
		class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">
		<property name="defaultFailureUrl" value="/"></property>
	</bean>
<!-- 未登录的切入点 -->
	<bean id="authenticationProcessingFilterEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
		<property name="loginFormUrl" value="/"></property>
	</bean>

	<context:component-scan base-package="clubgod.service" />
	<!-- 数据库配置 -->
	<bean id="dataSource"
    class="org.logicalcobwebs.proxool.ProxoolDataSource">
    <property name="driver">
        <value>com.mysql.jdbc.Driver</value>
    </property>
    <property name="driverUrl">
        <value>jdbc:mysql://10.10.8.8:3307/aaa?characterEncoding=utf8</value>
    </property>
    <property name="user" value="dev" />
    <property name="password" value="dev" />
    <property name="alias" value="Pool_dbname" />
    <property name="houseKeepingSleepTime" value="90000" />
    <property name="prototypeCount" value="0" />
    <property name="maximumConnectionCount" value="50" />
    <property name="minimumConnectionCount" value="2" />
    <property name="simultaneousBuildThrottle" value="50" />
    <property name="maximumConnectionLifetime" value="14400000" />
    <property name="houseKeepingTestSql" value="select CURRENT_DATE" />
</bean>

	<!-- myBatis文件 -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
	</bean>

	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="clubgod.dao,clubgod.mybatis.auto.dao,clubgod.security.resource" />
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
	</bean>

	<!-- 配置事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>

	<!-- 注解方式配置事物 -->
	<tx:annotation-driven transaction-manager="transactionManager" />

</beans>

4.cxf-beans.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:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
>
 <import resource="classpath:META-INF/cxf/cxf.xml" />
        <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
        <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
    <jaxws:endpoint id="validate" implementor="clubgod.cxf.service.impl.DemoImpl" address="/validate" />
</beans>

springMVC3+apache CXF+spring security3+mybatis3(proxool)整合项目

时间: 2024-10-05 06:17:57

springMVC3+apache CXF+spring security3+mybatis3(proxool)整合项目的相关文章

Error creating bean with name &#39;org.apache.cxf.spring.boot.autoconfigure.CxfAutoConfiguration

Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'org.apache.cxf.spring.boot.autoconfigure.CxfAutoConfiguration': Initialization of bean failed; nested exception

Apache CXF+Spring开发环境搭建小试

最近手上一个项目要开发webservice,而原有系统使用了spring,所以在选择框架的时候,我选择了cxf,这样在开发整合的时候就比较方便了.在搭建开发环境的过程中发现这篇文章写得比较详细,所以就搬到自己博客里,希望给自己和同行做参考. CXF 应用开发 下面就将开始我们的 CXF Web Services 的开发之旅!首先,要有一个基于 Eclipse 的开发环境:然后,我们将利用这个开发环境开发一个简单的“调查投票”示例,同时我们将解释一些 CXF 在开发中进行配置的基本方法. 开发环境

spring mvc +Mybatis3.1 整合的时候异常

在使用Mybatis3.10+spring3.10+mybatis-spring-1.0.0集成,使用spring 时发生例如以下错误: 严重: Servlet.service() for servlet SpringMVC threw exception java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransactionFactory.newTransaction(Ljava/sql/Co

新手使用Apache CXF的问题总汇

apache CXF 的创建需要几十个jar包依赖, 对于新手来说可能就是跳不完的坑 ,不断的查找jar下载jar 我当然也是这样一步步的跳了无数的坑,不过还好最终我成功了! 如下图是jar包依赖: 链接: http://pan.baidu.com/s/1hqnH2eg 密码: y4vw 你可能不相信 ,难道真的需要吗?这么多依赖包 ? 答案是肯定的,真的是这样的,一个也不能少 ,真心的建议大家使用maven进行项目管理,你将体会maven给你带来的所有便利!!!!!!! 几行pom  搞定一切

Spring+Struts2+Hibernate的整合

这篇主要采用Maven搭建Spring+Struts2+Hibernate的整合项目,复习一下SSH框架,虽然spring提供自己的MVC框架, 但是Spring也提供和其他框架的无缝整合,采用组件形式对个框架进行管理,项目实例是按照真实企业里面的开发搭建,也是web的最后一片了.数据库使 用mysql,连接池使用的是Druid数据源(这些都无关紧要,可以随时的替换),下面就将详细的介绍一下Maven搭建 Spring,Struts2,和hibernation的步奏. 1.数据库设计 数据库库表

Apache CXF 整合Spring

一.创建一个 Java Web 工程,目录最终的结构如下图,下面我们将遂一说明: 二.把我们要用到的jar包全部放到lib目录下. 三.修改web.xml文件,整合CXF. <?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2e

Apache cxf 整合 Spring MVC

1.添加依赖pom.xml <?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://maven.apache.o

Spring Security3 - MVC 整合教程 (初识Spring Security3)

下面我们将实现关于Spring Security3的一系列教程.最终的目标是整合Spring Security + Spring3MVC完成类似于SpringSide3中mini-web的功能. Spring Security是什么? 引用 Spring Security,这是一种基于Spring AOP和Servlet过滤器的安全框架.它提供全面的安全性解决方案,同时在Web请求级和方法调用级处理身份确认和授权.在Spring Framework基础上,Spring Security充分利用了

Apache CXF 整合 Map

在进行编码前有必要对一些基本的认识进行介绍,以便后面的讲解. 1.JAXB: JAXB能够使用Jackson对JAXB注解的支持实现(jackson-module-jaxb-annotations),既方便生成XML,也方便生成JSON,这样一来可以更好的标志可以转换为JSON对象的JAVA类.JAXB允许JAVA人员将JAVA类映射为XML表示方式,常用的注解包括:@XmlRootElement,@XmlElement等等. JAXB(Java Architecture for XML Bin