I have a webservice that I'm calling from a windows forms application (both .NET, both in the same solution), and I'd like my webservice to return a custom object from elsewhere in the project - it's a common object that they both share a reference to, as it's in the third project in my solution. When I call the webservice, it returns a "Person" object, but it's in the namespace of the webservice, and it's created from a proxy class …
我有自定义的分层模型,继承自QAbstractModelItem.此外,我实现了从QSortFilterProxyModel子类化的MySortFilterProxyModel.MySortFilterProxyModel可以删除和交换列.如果MySortFilterProxyModel中的第一列对应模型中的第一列,则一切正常.但如果它在代理模型中转换,则视图存在一些问题:MySortFilterProxyModel :: hasChildren工作正常,所以在顶层我有"+"附近有子节点的元素.但是当我尝试展开它时 - 不会显示任何子项.以下是一些MySortFilterProxyModel方法:
bool MySortFilterProxyModel::hasChildren(const QModelIndex &parent) const
{
if (parent.isValid() && parent.column() != 0)
return false;
QModelIndex source_parent = mapToSource(parent);
return sourceModel()->hasChildren( source_parent.sibling(source_parent.row(), 0) );
}
int MySortFilterProxyModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid() && parent.column() != 0)
return 0;
QModelIndex source_parent = mapToSource(parent);
return sourceModel()->rowCount( source_parent.sibling(source_parent.row(), 0) );
}
Run Code Online (Sandbox Code Playgroud)
在degugging期间,我发现MySortFilterProxyModel :: rowCount返回正确的数据.但我也注意到MyModel :: rowCount不是通过MySortFilterProxyModel :: rowCount调用的,而是来自QSortFilterProxyModel :: index().Peharps这是问题吗?
所以特别的问题是在层次模型中交换和关闭列的实现代理模型的正确方法是什么?
请帮我解决问题.谢谢.
我们都可能知道C++ 98 vector<bool>专门化将布尔值存储为位而不是bool变量.vector<bool>的元素是不可寻址的,因为C++没有指针和对位的引用,是否有解决方法,任何明显的陷阱(我似乎都没有注意到),甚至尝试这样做是否实用?
控制反转/面向方面意义上的代理对象是什么?
关于什么是代理对象的任何好文章?
为什么你想要使用一个?
如何在C#中编写一个?
我定义:
[ActiveRecord("BaseEntity", Lazy = true )]
class BaseClass {}
[ActiveRecord("DerivedEntity", Lazy = true )]
class DerivedClass : BaseClass {}
Run Code Online (Sandbox Code Playgroud)
在DB BaseEntity和DerivedEntity中,1 = 1
我创造:
BaseClass myClass = New DerivedClass();
Run Code Online (Sandbox Code Playgroud)
问题:
当我试着问
myClass is DerivedClass
Run Code Online (Sandbox Code Playgroud)
我得到"假",因为myClass不是DerivedClass而是BaseClassProxy.
没有延迟加载,NHibernate不会创建代理对象,我没有这个问题.
当我尝试将myClass转换为DerivedClass时,我得到了这个错误(显然),因为我尝试将BaseClassProxy对象强制转换为DerivedClass.
Unable to cast object of type 'Castle.Proxies.BaseClassProxy' to type 'DerivedClass'.
Run Code Online (Sandbox Code Playgroud)
问题:
如何获取实际分配的对象类型以将其与DerivedClass进行比较?
是否可以转换BaseClassProxy对象以获取DerivedClass的实例?
感谢您的答复.
任何人都知道如何将依赖项注入@ControllerAdvice?
我的@ControllerAdvice扩展了Spring的ResponseEntityExceptionHandler并且没有实现任何接口。
@ControllerAdvice 被正确调用,但 @Autowired 依赖项从未被注入。没有启动注入错误,依赖项只是空的。
我想这与 Spring 如何使用 cglib 代理 @ControllerAdvice 以使 @Autowired 注释丢失有关。
我通过实现一个接口进行测试,这样Spring可以创建一个JDK代理,但它也不起作用。实际上,对于一个接口,它甚至根本没有被调用......即使我也用 @ControllerAdvice 注释该接口。
有没有办法指定 Spring 在特定情况下应使用 JDK 代理?
编辑:顺便说一句,我正在使用 Spring 3.2.4.RELEASE。
示例类:
@ControllerAdvice
public class RestExceptionHandler extends ResponseEntityExceptionHandler {
@Autowired(required = true)
public AuditService auditService;
@ExceptionHandler(value = { RuntimeException.class })
public final ResponseEntity<Object> handleRuntimeException(Exception ex, WebRequest request) {
// auditService is null here!
}
}
Run Code Online (Sandbox Code Playgroud) 我想在 UserService(具体类)的 save() 方法中使用 @Transactional 注释,如下所示:
@Service
public class UserService {
@Transactional
public Long save(User userCommand, BindingResult result) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
我将通过自动装配在 MyRealm 中使用此服务。
public class MyRealm extends AuthorizingRealm {
@Autowired
private UserService userService;
}
Run Code Online (Sandbox Code Playgroud)
但是,它失败并出现以下错误:
java.lang.IllegalArgumentException: Can not set n.r.c.s.user.UserService field n.r.c.s.realm.MyRealm.userService to com.sun.proxy.$Proxy48
Run Code Online (Sandbox Code Playgroud)
当然,如果我删除 @Transational 注释,它会起作用。
我的事务管理器设置如下:
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
Run Code Online (Sandbox Code Playgroud)
请让我知道我的代码有什么问题?
我需要设置代理之类的东西吗?
根据我关于WCF 服务返回值的另一篇文章,我正在使用另一家公司的 Web 服务,当我在 Visual Studio 中添加服务引用时,该方法的返回值是类型为 的对象object。
Web 服务的作者向我展示了代码,它实际上返回了一个类型化的对象。
我是否遗漏了某些内容,或者代理类是否应该返回键入的值?
是否有用于生成代理类或实际服务的设置?
更新:
我查看了 WCF 服务背后的实际类,并意识到服务方法的返回值实际上是返回具体类型实现的接口。具体类型用 [DataContract] 属性(和适当的 [DataMember] 属性)标记,但接口没有这样的属性。这是否会导致服务将返回类型设置为对象?
我有很多的记录,类似的方法logSomeAction,logAnotherAction等等.
现在我希望所有这些方法在打印消息(Thread.sleep)后暂停一小段时间.
如果我手动完成,我会做这样的事情:
//before:
public static void logSomeAction () {
System.out.println (msg(SOME_ACTION));
}
//after:
public static void logSomeAction () {
System.out.println (msg(SOME_ACTION));
try {
Thread.sleep (2000);
} catch (InterruptedException ignored) { }
}
Run Code Online (Sandbox Code Playgroud)
我记得Java有代理类和其他一些魔术制作工具.有没有办法避免将N个睡眠块复制粘贴到N个记录方法?
我们一直在使用@Autowired基于Java的Spring配置并取得了一些成功,但现在我们失去了控制权.每个人都开始在任何地方添加自动连接的依赖项,创建周期和奇怪的错误.
所以我们正在考虑使用构造函数注入和Spring配置的自动装配.
旧:
class Bean {
@Autowired Foo foo;
}
@Configuration
@Import( FooCfg.class )
class BeanCfg {
@Bean public Bean bean() { return new Bean(); }
}
Run Code Online (Sandbox Code Playgroud)
新:
class Bean {
public Bean(Foo foo) {...}
}
@Configuration
class BeanCfg {
@Autowired FooCfg fooCfg;
@Bean public Bean bean() { return new Bean(fooCfg.foo()); }
}
Run Code Online (Sandbox Code Playgroud)
这非常有效(并且它驱使人们分割bean而不是创建具有10个以上构造函数参数的怪物).
但是当Bean有一个方法注释时它会失败,@Transactional因为CGLIB然后尝试创建一个失败的代理,因为它找不到无参构造函数.
这是什么解决方案?
proxy-classes ×10
c# ×3
spring ×3
.net ×2
cglib ×2
aop ×1
asp.net ×1
autowired ×1
bitvector ×1
boolean ×1
c++ ×1
casting ×1
class ×1
java ×1
jpa ×1
lazy-loading ×1
model ×1
nhibernate ×1
qt ×1
return-value ×1
stdvector ×1
wcf ×1
web-services ×1