问题描述
我有一个jython servlet作为在tomcat5中运行的大型应用程序的一部分。我测试了一些Spring Framework类并在Jython servlet中创建了对象。当我尝试在应用程序中创建类的对象时,我捕获一个异常消息没有类的可见构造函数。这些java类有一个公共构造函数类,例如:
I have a jython servlet as part of a large application running in tomcat5. I tested a few Spring Framework classes and create the objects in the Jython servlet. When I try to create objects of classes in the application I catch an Exception message "No visible constructors for class". These java classes do have a public constructor class, such as:
public SchoolImpl(){
}
我在python中创建对象:
I create the object in python:
来自com .dc.sports.entity import SchoolImpl
...
school = SchoolImpl()
什么是我做错了?
推荐答案
doublep / cluch在评论中回答了问题:-)
doublep / cluch answered the question :-) in the comment
只添加一些信息:
来自Jython FAQ:
From the Jython FAQ :
3.3为什么我不能执行'受保护'或'私有'Java实例方法或访问Java包中的'protected'或'private'属性?
默认情况下,与Java一样,这些方法受到保护,不受外部访问。可以使用python.security.respectJavaAccessibility注册表设置启用对所有Java字段和方法的访问:
By default, as in Java, these methods are protected from external access. Access to all Java fields and methods can be enabled with the python.security.respectJavaAccessibility registry setting:
# Setting this to false will allow Jython to provide access to
# non-public fields, methods, and constructors of Java objects.
python.security.respectJavaAccessibility = false
这篇关于Jython说“没有类可见的构造函数”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!