对于启用IncludeExceptionDetailInFaults感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍通过ServiceBehaviorAttribute或配置行为,并为您提供关于
对于启用IncludeExceptionDetailInFaults感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍通过ServiceBehaviorAttribute或 配置行为,并为您提供关于ASP.NET Core-ActionFilter实现依赖注入(ServiceFilterAttribute 、TypeFilterAttribute) 【转】、BeanCreationNotAllowedException: Error creating bean with name ''eurekaAutoServiceRegistration...、Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':classpath'.、Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet的有用信息。
本文目录一览:- 启用IncludeExceptionDetailInFaults(通过ServiceBehaviorAttribute或 配置行为)
- ASP.NET Core-ActionFilter实现依赖注入(ServiceFilterAttribute 、TypeFilterAttribute) 【转】
- BeanCreationNotAllowedException: Error creating bean with name ''eurekaAutoServiceRegistration...
- Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':classpath'.
- Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
启用IncludeExceptionDetailInFaults(通过ServiceBehaviorAttribute或 配置行为)
我有一个运转良好的WCF服务,并且某些更改了,我不知道是什么。
我得到这个例外:
System.ServiceModel.FaultException:由于内部错误,服务器无法处理请求。有关错误的更多信息,请打开服务器上的IncludeExceptionDetailInFaults(从ServiceBehaviorAttribute或从配置行为),以便将异常信息发送回客户端,或者根据Microsoft
.NET Framework 3.0 SDK文档打开跟踪。并检查服务器跟踪日志。
这令人困惑,因为我正在运行.NET 4.0。
我在哪里打开IncludeExceptionDetailInFaults
?我正在努力寻找它。
答案1
小编典典在文件中定义行为.config
:
<configuration> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="debug"> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors> ... </system.serviceModel></configuration>
然后按照以下方式将行为应用于您的服务:
<configuration> <system.serviceModel> ... <services> <service name="MyServiceName" behaviorConfiguration="debug" /> </services> </system.serviceModel></configuration>
您也可以通过编程进行设置。看到这个问题。
ASP.NET Core-ActionFilter实现依赖注入(ServiceFilterAttribute 、TypeFilterAttribute) 【转】
一、简介
前几篇文章都是讲ASP.NET Core MVC中的依赖注入(DI)与扩展点的,也许大家都发现在ASP.NET CORE中所有的组件都是通过依赖注入来扩展的,而且面向一组功能就会有一组接口或抽象工厂来扩展功能,就如IControllerActivator这样的功能点在上篇文章(查看.NET Core源代码通过Autofac实现依赖注入到Controller属性)中也提到了,今天我们主要介绍一个大类似的扩展点,ASP.NET Core MVC中为我们提供了新的机制为Action Filters(也就是过滤器)进行依赖注入的扩展。
二、过滤器依赖注入
在ASP.NET Core MVC中,框架中为我们提供了类型为 IFilter 的 Attributes 来装饰Action,用于拦截Action请求,这有在以前的版本中就有了,但是如果我们想结合依赖注入使用的话要使用IFilterFactory接口来扩展Action Filter的创建过程。
2.1 IFilterFactory接口定义
public interface IFilterFactory : IFilter
{
IFilter CreateInstance([NotNull] IServiceProvider serviceProvider);
}
我们想要创建一个Filter Attribute并需要依赖注入的话一般想要的代码为:

public class FilterClass : ActionFilterAttribute
{
public FilterClass(IDependency1 dependency1, IDependency2 dependency2)
{
// ...use dependencies
}
}

ASP.NET Core MVC中为我们提供了两种简单的IFilterFactory : ServiceFilterAttribute 和 TypeFilterAttribute 。来个例子看看怎么使用。

public class HomeController: Controller
{
[TypeFilter(typeof(FilterClass))]
[ServiceFilter(typeof(FilterClass))]
public IActionResult Index()
{
return View();
}
}

2.2 ServiceFilterAttribute
其实看到名字,有些朋友就能想到了,它是基于依赖注入的一个IFilterFactory,Service这个词强化了它是一个通过获取服务来实现依赖注入的,大家想到了什么?是不是GetService()? 没错,其实它的机制就是这个。
要使用ServiceFilter就必须在依赖注入容器里注册对应的类型,比如下面的例子就要先将FilterClass类型注册到IOC容器里。
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<FilterClass>();
services.AddMvc()
}
当然如果FilterClass类型的构造器需要注入类型时,也需要在IOC容器里进行注册才可以使用。
我们来看下ServiceFilterAttribute的源代码:

public class ServiceFilterAttribute : Attribute, IFilterFactory, IOrderedFilter
{
public ServiceFilterAttribute([NotNull] Type type)
{
ServiceType = type;
}
public Type ServiceType { get; private set; }
public int Order { get; set; }
public IFilter CreateInstance([NotNull] IServiceProvider serviceProvider)
{
var service = serviceProvider.GetRequiredService(ServiceType);
var filter = service as IFilter;
if (filter == null)
{
throw new InvalidOperationException(Resources.FormatFilterFactoryAttribute_TypeMustImplementIFilter(
typeof(ServiceFilterAttribute).Name,
typeof(IFilter).Name));
}
return filter;
}
}

2.3 TypeFilterAttribute
当然你也可以选择使用这个类似于ServiceFilter过滤器的TypeFilter过滤器,它也同样实现了IFilterFactory接口,并可以通过它创建出可使用依赖注入的过滤器来。之所以叫TypeFilter就是因为它并不需要在依赖注入容器里注册类型就能创建出过滤器, 我们来看下它的代码:

public class TypeFilterAttribute : Attribute, IFilterFactory, IOrderedFilter
{
private ObjectFactory factory;
public TypeFilterAttribute([NotNull] Type type)
{
ImplementationType = type;
}
public object[] Arguments { get; set; }
public Type ImplementationType { get; private set; }
public int Order { get; set; }
public IFilter CreateInstance([NotNull] IServiceProvider serviceProvider)
{
if (this.factory == null)
{
var argumentTypes = Arguments?.Select(a => a.GetType())?.ToArray();
this.factory = ActivatorUtilities.CreateFactory(ImplementationType, argumentTypes ?? Type.EmptyTypes);
}
return (IFilter)this.factory(serviceProvider, Arguments);
}
}

三、结语
相信看过上一篇文章的朋友都注意到了ServiceProvider和ActivatorUtilities 的不同,本文中的ServiceFilterAttribute和 TypeFilterAttribute 原理上也是通过它们来创建Filter的,所以使用场景就看大家如何来使用。其实最近看.NET Core的源代码,看到的到处都是接口、工厂使用依赖注入形成扩展点的例子,其实微软以前代码的扩展点也挺多的,只是API并不那么开放,ASP.NET Core中我们看到了一个"开放"的框架。
BeanCreationNotAllowedException: Error creating bean with name ''eurekaAutoServiceRegistration...
- 原代码
@EnableDiscoveryClient
@EnableCircuitBreaker
@EnableFeignClients
@SpringBootApplication
public class WebappApplication{
public static void main(String[] args) {
SpringApplication.run(WebappApplication.class, args);
}
}
- 修改后代码
@EnableDiscoveryClient
@EnableCircuitBreaker
@EnableFeignClients
@SpringBootApplication
public class WebappApplication implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
BeanDefinition bd = beanFactory.getBeanDefinition("feignContext");
bd.setDependsOn("eurekaServiceRegistry", "inetUtils");
}
public static void main(String[] args) {
SpringApplication.run(WebappApplication.class, args);
}
}
- 我是执行后发现 tomcat 端口被占用,然后 win 中查看端口也没发现端口被占用,索性就换了个端口,然后 run, 然后就 Congratulations!!!!!!
- 更
- 发现用 cmd 找不到的端口
netstat -ano| findstr "8002"
- 8002 是端口号
- 而用 powershell 却可以
Get-Process -Id (Get-NetTCPConnection -LocalPort 8002).OwningProcess
- 8002 是端口号
- 然后 kill 一波
taskkill /F /PID 6640
- 6640 是 pid
- 发现用 cmd 找不到的端口
- 参考链接: https://github.com/spring-cloud/spring-cloud-netflix/issues/1952#issuecomment-322669642
- 参考链接: https://winaero.com/blog/kill-process-windows-10/
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':classpath'.
前言
这个错误怎么看呢?
如果你对gradle 不是很了解的话,有一个建议,就是把异常背下来,当然是看这个:ArtifactResolveException哈。
而不是后面的详情。
正文
给我们详情是这个:
Could not resolve all files for configuration '':classpath''.
其实就是说文件缺少。
然后我们看旁边的。
这是一个错误栈,你最好需要点开每一个。
我打开了其中一个详细内容,告诉我们有一个包下载不下来。
接着你不要马上去弄什么代理,你应该尝试是否这个包已经不存在了,因为可能有些包的确失效了,接着你才应该考虑代理。
总结
以上是小编为你收集整理的Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration '':classpath''.全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:281)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:255)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:528)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:153)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:178)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy91.save(Unknown Source)
at com.qingmu.seller.reposity.ProductCategoryReposityTest.saveTest(ProductCategoryReposityTest.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:67)
at org.hibernate.id.enhanced.SequenceStructure$1.getNextValue(SequenceStructure.java:95)
at org.hibernate.id.enhanced.NoopOptimizer.generate(NoopOptimizer.java:40)
at org.hibernate.id.enhanced.SequenceStyleGenerator.generate(SequenceStyleGenerator.java:520)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:120)
at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:192)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:135)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:62)
at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:108)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:702)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:688)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:314)
at com.sun.proxy.$Proxy86.persist(Unknown Source)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.save(SimpleJpaRepository.java:554)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:371)
at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:204)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:657)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:621)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:605)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:366)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:99)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
... 38 more
Caused by: java.sql.SQLSyntaxErrorException: FUNCTION seller.nextval does not exist
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1003)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:57)
... 72 more
使用 springDataJPA 时候,因为数据库方言设置不正确,报错为上面的信息.
修改一下数据库中配置的方言
jpa:
hibernate:
ddl-auto: create
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
show-sql: true
解决这个问题,
还有一种就是数据库中的字段和实体类中的名称对应不上,也会报这个错误
今天关于启用IncludeExceptionDetailInFaults和通过ServiceBehaviorAttribute或 配置行为的介绍到此结束,谢谢您的阅读,有关ASP.NET Core-ActionFilter实现依赖注入(ServiceFilterAttribute 、TypeFilterAttribute) 【转】、BeanCreationNotAllowedException: Error creating bean with name ''eurekaAutoServiceRegistration...、Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':classpath'.、Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet等更多相关知识的信息可以在本站进行查询。
本文标签: