我的应用服务器ibm websphere.我在应用程序服务器日志中收到以下错误.我在哪里可以进行websphere设置?
[19.09.2012 14:56:54:940 EEST] 0000000a SystemErr R SLF4J:类路径包含多个SLF4J绑定.
[19.09.2012 14:56:54:940 EEST] 0000000a SystemErr R SLF4J:在[wsjar:file:/ C:/Lib/slf4j-log4j12-1.6.1.jar!/ org/slf4j/impl/StaticLoggerBinder中找到绑定.class]
[19.09.2012 14:56:54:941 EEST] 0000000a SystemErr R SLF4J:在[bundleresource://217.fwk37356669:1/org/slf4j/impl/StaticLoggerBinder.class]中找到绑定
[19.09.2012 14 :56:54:941 EEST] 0000000a SystemErr R SLF4J:请参阅http://www.slf4j.org/codes.html#multiple_bindings以获得解释.
class abc {
int a = 0;
static int b;
static abc h = new abc(); //line 4
public abc() {
System.out.println("cons");
}
{
System.out.println("ini");
}
static {
System.out.println("stat");
}
}
public class ques {
public static void main(String[] args) {
System.out.println(new abc().a);
}
}
Run Code Online (Sandbox Code Playgroud)
当我写这段代码时,我按顺序得到输出:
ini
cons
stat
ini
cons
0
Run Code Online (Sandbox Code Playgroud)
这里当我在main(), class abc加载中创建一个新对象时,static变量和块按顺序执行.当控制进入第4行时,static abc h = new abc();将调用实例初始化块.为什么?为什么在第4行创建新对象时不调用静态块,直到那时静态块也没有被调用一次,所以根据惯例,应该调用静态块.为什么会出现这种意外的输出?
根据Swagger的教程,似乎swagger只支持Jersey框架(参见https://github.com/wordnik/swagger-core/wiki/java-jax-rs)
有没有人有过使用CXF JAX-RS实现大摇大摆的经验?你能在这里分享你的建议吗?
调用JSF交叉字段验证的类级JSR-303约束的最佳方法是什么,并将结果消息转换为FacesMessage并绑定到基于ConstraintViolation中的PropertyPath的特定JSF组件?
rich:graphValidator很接近,但它没有使用PropertyPath.也许MyFaces的延期可以让我接近,但是在bean验证的时候似乎有一整套额外的框架,所以我避免了它.
这是一个简单的例子:
public enum Type {
ROAD, RACE;
}
public class Driver {
private String name;
private Type licenseType;
...
}
@CarConstraint
public class Car {
@Valid
private Driver driver;
private Type carType;
private String make;
private String model;
...
}
public class CarConstraintValidator implements ConstraintValidator<CarConstraint, Car>{
@Override
public void initialize(CarConstraint constraintAnnotation) {}
@Override
public boolean isValid(Car value, ConstraintValidatorContext context) {
if(value == null) {return true;}
if(Type.RACE.equals(value.getCarType())
&& !Type.RACE.equals(value.getDriver().getLicenseType())) {
context.buildConstraintViolationWithTemplate("Driver of this car must have a racing …Run Code Online (Sandbox Code Playgroud) 我正在将我的项目从Spring 3.0 + hibernate 3.6.x迁移到S3.1 + H4.1
我的新代码如下
<context:component-scan base-package="x.y.z">
</context:component-scan>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.x</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>x.y.z.entities.Student</value>
</list>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<aop:config>
<aop:pointcut id="daoServicePoint"
expression="execution(* x.y.z.StudentDao.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="daoServicePoint"/>
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
</tx:attributes>
</tx:advice>
Run Code Online (Sandbox Code Playgroud)
当运行getStudent方法标记为SUPPORTS并且只读我正在获取
org.hibernate.HibernateException: No Session found for current thread …Run Code Online (Sandbox Code Playgroud) 我最近在JSP中开发了一个tomcat web应用程序,它使用绑定到公司Active Directory的声明性安全性(server.xml/web.xml).我被要求为刚刚起步的项目添加JSF支持.将登录表单转换为jsf是一件简单的事情,安全模型仍然有效.
一位员工询问我是否允许更广泛的受众查看其中一个报告,但仅为较小的组呈现操作按钮.作为JSF的新手,我不得不做一些研究.
我花了大约四个小时来搜索诸如"jsf按钮安全性"和"jsf按钮权限"之类的内容,并尝试了大多数死路一条的各种建议.另一位同事建议使用Spring安全模型,但如果有更简单的方法,我不想处理一大堆Spring库.
最后,我偶然发现了答案,这非常简单.我只需要使用HttpServletRequest方法:isUserInRole()来确定当前登录的用户是否有权查看操作按钮.在过去的十年里,我已经使用了很多HttpServletRequests,但我不记得曾经学过这种方法.使用jsf,获得该方法很简单,如下所示:
public boolean isUserInRole(String role) {
return (FacesContext.getCurrentInstance().getExternalContext().isUserInRole(role));
}
Run Code Online (Sandbox Code Playgroud)
我的问题具体是:我是否应该注意这种方法的问题,还有另一种更简单的方法吗?
我在我的JPA项目Eclipselink中使用NanedQueries(如下所示)作为持久性提供程序:
@Entity
@Table(name = "login")
@NamedQueries({
@NamedQuery(name = "Login.random", query = "SELECT l FROM Login l WHERE l.pk = :randomPk"),
@NamedQuery(name = "Login.max", query = "SELECT MAX(l.pk) FROM Login l")
})
Run Code Online (Sandbox Code Playgroud)
但在我将Hibernate更改为持久性提供程序后,我收到以下错误:
java.lang.IllegalArgumentException: org.hibernate.QueryException: unexpected char: '{' [SELECT...
Run Code Online (Sandbox Code Playgroud)
我使用Hibernate 3.2.5(MySQL方言)
具有以"/"开头的值与没有它的@Path之间是否存在差异
我测试了两种用法,都正常工作.
@Path("message")
public class MessageServices {
@PUT
@Path("sendsms")
@Consumes(MediaType.APPLICATION_JSON)
@Produces({MediaType.APPLICATION_JSON})
public Response sendSms() {
//....
}
}
@Path("/message")
public class MessageServices {
@PUT
@Path("/sendsms")
@Consumes(MediaType.APPLICATION_JSON)
@Produces({MediaType.APPLICATION_JSON})
public Response sendSms() {
//....
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个配置了Spring Security处理身份验证的Jersey应用程序.jersey-spring包提供了SpringServlet类,它在我的web.xml中作为servlet注册.
身份验证和所有工作按预期.我想知道的是如何通过Jersey servlet发送AuthenticationExceptions(以及其他过滤器异常),因此我可以使用我们的ExceptionMapper来处理它们.
最初SpringServlet被配置为过滤器,但在做了一些阅读之后,我开始明白servlet应该能够处理过滤器中抛出的异常(可能这是一个错误的理解).在将其更改为servlet后,我没有注意到行为的任何变化,如果我追踪Spring Security代码,我可以看到HttpServletResponse的编写位置.
我的问题:是否有可能让Jersey servlet进程抛出Spring Security过滤器引发的异常?
我正在测试内存模式下的H2 DB.我建立了一个连接
h2Con = DriverManager.getConnection(
"jdbc:h2:mem:db1", "SA", "");
Run Code Online (Sandbox Code Playgroud)
我想用dbunit进行一些导入并设置dbUnits数据库连接
IDataBaseConnection dBUnitConnection = new DatabaseConnection(h2con);
Run Code Online (Sandbox Code Playgroud)
以及我想稍后查询的导入
所以我的问题是,在内存模式下,何时可以关闭连接?Normaly我做这样的事情
try{
//some sql query
}catch{
//error handling
}finally{
if(connection!=null)
connection.close()
}
Run Code Online (Sandbox Code Playgroud)
但是在内存中,如果连接关闭,我会丢失数据?所以它应该保持开放,直到我结束我的程序?
我需要申报
private final EventListener<Event> eventListener;
Run Code Online (Sandbox Code Playgroud)
但发生以下错误
org.zkoss.zk.ui.event.EventListener does not take parameter.
Run Code Online (Sandbox Code Playgroud)
在文章这个链接http://java.dzone.com/articles/advanced-zk-asynchronous-ui使用它.怎么用这个命令?
package ali;
public class test {
public static int n = 99;
public static test t1 = new test("t1");
public static test t2 = new test("t2");
public static int i = 0;
public static int j = i;
{
System.out.println("construct block");
}
static {
System.out.println("static construct block");
}
public test(String str){
System.out.println((++j) + ":" + " i="+ i + " n="+n+str);
n++;i++;
}
public static void main(String [] args){
test test1 = new test("initl");
}
}
Run Code Online (Sandbox Code Playgroud)
跑完后:
construct block
1: …Run Code Online (Sandbox Code Playgroud)