Git Product home page Git Product logo

exception's Introduction

unified exception framework(统一的异常框架) config目录下是相关配置文件,如果使用了spring的话,请把相关配置import到spring的上下文配置文件里,相关占位符${}需要设置具体的值。

exception.xml 异常处理的主要配置:

<!-- responsibility chain for exception handle -->
<bean id="exceptionHandlerChain"
	class="ExceptionHandlerChain">
	<property name="chain">
		<list>
			<bean id="logBackExceptionHandler"
				class="LogBackExceptionHandler">
				<property name="level" value="3" />
			</bean>
			<!--如果配置了mongodb异常处理resolver,则需要配置mongodb-context.xml,否则不需要-->
			<bean id="mongoDBExceptionHandler"
				class="MongoDBExceptionHandler">
				<property name="level" value="2" />
				<property name="asynFlag" value="true" /property>
			</bean>
		</list>
	</property>
</bean>

<!-- thread pool for asyn handle -->
<!--如果异常处理resolver没有设置异步处理(asynFlag=true的)的话,不需要配置exceptionHandleExecutor-->

<bean id="exceptionHandleExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
	<property name="threadNamePrefix" value="exceptionHandleExecutor" />
	<property name="corePoolSize" value="20" />
	<property name="maxPoolSize" value="20" />
	<property name="queueCapacity" value="100000" />
</bean>

<!-- exception manager -->
<bean id="exceptionManager" class="ExceptionManager">
	<property name="systemCode" value="YOUR SYSTEM CODE" />
	<property name="ehc" ref="exceptionHandlerChain" />
	<property name="exceptionHandleExecutor" ref="exceptionHandleExecutor"/>
</bean>

<!--切面配置,建议是将切面加在最上层,比如我这里是Controller-->
<!-- aop config -->
<aop:config>
	<aop:pointcut id="unifiedException"
		expression="execution(* com..*Controller.*(..))" />
	<aop:advisor advice-ref="unifiedExceptionThrowsAdvice"
		pointcut-ref="unifiedException" />
</aop:config>
<!-- throw advice -->
<bean id="unifiedExceptionThrowsAdvice"
	class="UnifiedExceptionThrowsAdvice">
	<property name="exceptionManager" ref="exceptionManager" />
</bean>

mongodb-contexnt.xml 记录异常日志到mongodb的配置:

<!-- Connection to MongoDB server -->
<mongo:db-factory host="${mongo.host}" port="${mongo.port}" dbname="${mongo.dbname}" username="${mongo.user}" password="${mongo.password}" />

<!-- MongoDB Template -->
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
    <constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
</bean>

<!-- mongo repositories -->
<mongo:repositories base-package="com.roirrow.common.exception.handler.repository" />

exception's People

Contributors

roirrow avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.