小编Bru*_*sar的帖子

在JAX-RS上使用UriBuilder的AbstractMethodError

我正在尝试使用异步响应构建REST Web服务.

我在网上查看了这个错误,但是,没有一个解决方案对我有用.我不确定如何去做.

这是REST服务的代码,它有AsyncResponse,@Suspended它取自pom.xml我指定的jar文件,我将在下面提供.问题是,在部署战争时,我得到一个例外:

java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
    javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:651)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.50 logs
Run Code Online (Sandbox Code Playgroud)

我的班级如下:

package com.crudapp;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import javax.annotation.Generated;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
//import javax.ws.rs.core.UriBuilder;

import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.google.gson.Gson;
import com.mysql.jdbc.StringUtils;

import dao.User;
import dao.UserDAO;
import dao.UserDAOImpl;

import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;

@Path("/crudpath") …
Run Code Online (Sandbox Code Playgroud)

java jax-rs jersey maven

31
推荐指数
2
解决办法
7万
查看次数

IllegalStateException:没有在单元测试中为范围'session'注册的Scope

我有一个mkyong MVC教程的修改版本.

我添加了一个业务层类Counter.

public class Counter {

    private int i;


    public int count()
    {
        return (this.i++);
    }

    //getters and setters and constructors
}
Run Code Online (Sandbox Code Playgroud)

在mvc-dispatcher-servlet.xml中:

<bean id="counter" class="com.mkyong.common.Counter" scope="session">
    <property name="i" value="0"></property>
</bean>
Run Code Online (Sandbox Code Playgroud)

这很好用.

我现在想为这个类创建一个单元测试

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration()

public class TestCounter {

    @Configuration
    static class TestConfig
    {
        @Bean
        public Counter c()
        {
            return new Counter();
        }
    }

    @Autowired
    private Counter c;

    @Test
    public void count_from1_returns2()
    {
        c.setI(1);
        assertEquals(2, c.count());

    }

}
Run Code Online (Sandbox Code Playgroud)

如果我像这样运行它,我会得到的

SEVERE: Caught exception while allowing …
Run Code Online (Sandbox Code Playgroud)

java spring-mvc junit4

8
推荐指数
1
解决办法
1万
查看次数

Null GrantedAuthority获取Spring Security上的UserDetails

这是我在Spring安全性中的UserDetails服务:

public class UserDetail implements UserDetailsService {

    @Autowired
    User_service user_service;

    @Override
    public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException {
        boolean enabled = true;
        boolean accountNonExpired = true;
        boolean credentialsNonExpired = true;
        boolean accountNonLocked = true; 
        com.domain.User user = user_service.findByUserName(userId);
        return new User(user.getUserId(), user.getPassword(), enabled,
                            accountNonExpired, credentialsNonExpired, 
                            accountNonLocked, this.getGrantedAuthorities(user));
    }

    public List<GrantedAuthority> getGrantedAuthorities(com.domain.User user) {
        List<GrantedAuthority> role_name = null;
        List<Role> roles = user.getRoles();
        try {
            for(Role role : roles) {
                role_name.add(new GrantedAuthorityImpl(role.getName()));
            }
        } catch(Exception ex) {
            System.out.println(ex.toString());
        }
        return role_name;
    } …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security

6
推荐指数
1
解决办法
1万
查看次数

使用 Docker 时未加载 Keycloak SPI 提供程序和层

我正在尝试使用一些自定义内容(例如 logback 扩展)设置 docker 映像,因此我有一些 CLI 脚本,如下所示:

/subsystem=logging: remove()
/extension=org.jboss.as.logging: remove()

/extension=com.custom.logback: add()
/subsystem=com.custom.logback: add()
Run Code Online (Sandbox Code Playgroud)

我还有 CLI 脚本来配置数据源池、主题、在keycloak-server子系统上添加一些 SPI 等。我将这些脚本放在/opt/jboss/startup-scripts目录中。但是,当我创建容器时,事情运行得不太好。脚本未按预期加载,并且 keycloak 启动时出现错误,未加载领域使用的密码策略等提供程序。

当我使用独立的 Keycloak 时,所有 SPI 提供程序都会正常加载,如下日志所示:

2019-07-25 18:27:07.906 WARN  [org.keycloak.services] (ServerService Thread Pool -- 65) KC-SERVICES0047: custom-password-policy (com.custom.login.password.PasswordSecurityPolicyFactory) is implementing the internal SPI password-policy. This SPI is internal and may change without notice
2019-07-25 18:27:07.909 WARN  [org.keycloak.services] (ServerService Thread Pool -- 65) KC-SERVICES0047: custom-event (com.custom.event.KeycloakServerEventListenerProviderFactory) is implementing the internal SPI eventsListener. This SPI is internal …
Run Code Online (Sandbox Code Playgroud)

docker wildfly keycloak

5
推荐指数
1
解决办法
5429
查看次数

如何生成随机字符串?

这是我正在使用的一段代码,但是,我想生成关于我设置的字符串的随机响应.如何最好地接近这个?也许只是为了澄清,我需要随机输出"Hello","Good day","bye","告别",而不是列出它们的顺序.

public void run() {
    String importantInfo[] = {
          "Hello",
          "Good day",
          "bye",
          "farewell"
    };

    Random random = new Random();

    for (int i = 0; i < importantInfo.length; i++) {
        drop.put(importantInfo[i]);
        try {
            Thread.sleep(random.nextInt(5000));
        } catch (InterruptedException e) {}
    }
    drop.put("DONE");
}
Run Code Online (Sandbox Code Playgroud)

java string random

2
推荐指数
1
解决办法
409
查看次数

每个类的Arraylist的JSTL

使用Adobe CQ 5.5和JSP作为组件对象.在JSTL中返回结果有些麻烦.

我有一个自定义类的数组.

private static class Asset {

   private String displayname;

   public Asset(){
   }

   public String getDisplayName() {
      return displayname;
   }

   public void setDisplayName(String displayname) {
       this.displayname = displayname;
   }

}
Run Code Online (Sandbox Code Playgroud)

这个片段有效,但我想使用JSTL

  for (int i = 0; i < assets.size(); i++) {
      Asset c = assets.get(i);                        
      out.println(c.displayname + "<BR>");    
  }
Run Code Online (Sandbox Code Playgroud)

这就是我想要做的:

 request.setAttribute("assetList",assets);
%>

<c:forEach items="${assetList}" var="item" varStatus="status">
   <p>Title:</p> 
   ${item.displayname}
</c:forEach>
Run Code Online (Sandbox Code Playgroud)

JSTL确实返回了4个项目,例如工作示例,但是只要我添加${item.displayname},我就会收到错误.

Caused by: javax.el.PropertyNotFoundException: Property 'displayname' not found on type org.apache.jsp.apps.pnc_002dideas.components.homepage.slider.slider_jsp$Asset
    at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:193)
    at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:170)
    at javax.el.BeanELResolver.property(BeanELResolver.java:279) …
Run Code Online (Sandbox Code Playgroud)

jsp aem

0
推荐指数
1
解决办法
1339
查看次数

如何对LocalDateTime排序并获取最大和最小?

任何人都可以共享对LocalDateTime排序并从域对象列表中获取最大和最小记录的逻辑。

域对象

private int employeeNumber;
private LocalDateTime updatedDate;
Run Code Online (Sandbox Code Playgroud)

第一记录

1.1,2016-07-09 00:00:00+0000
2.2,2017-10-06 23:25:37+0000
Run Code Online (Sandbox Code Playgroud)

最大输出:2,2017-10-06 23:25:37 + 0000

最小输出:1,2016-07-09 00:00:00 + 0000

java-8

0
推荐指数
2
解决办法
6907
查看次数