小编Dea*_*ean的帖子

用于Spring Oauth端点的模拟服务器

我正在尝试进行集成测试,以查看我的注册端点失败时的行为。我的注册端点是由外部来源提供的API(由Spring OAuth保护)。客户端网站正在使用客户端Spring Oauth与API进行通信。

我想做的是模拟API,但是,我遇到了一些问题,即请求没有针对模拟端点进行;org.springframework.web.client.ResourceAccessException:“ http:// localhost:8081 / oauth / token ”的POST请求出现I / O错误:拒绝连接:connect; 嵌套的异常是java.net.ConnectException:拒绝连接:connect。以下是我的测试:

 @WebAppConfiguration
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(locations = {"classpath*:RegistrationControllerIntegrationTest-context.xml"})
 public class RegistrationControllerIntegrationTest {


  @Resource
  RegistrationController registrationController;

  @Resource
  private WebApplicationContext webApplicationContext;

  MockMvc mockMvc;

  @Value("${oauth.accessTokenUri}")
  private String oauthUri;

  private MockRestServiceServer mockRestServiceServer;


  private OAuth2RestTemplate clientCredRest;


  @Resource(name = "clientCredentialRest")
  public void setClientCredRest(OAuth2RestTemplate clientCredRest) {
    this.clientCredRest = clientCredRest;
  }



  @Before
  public void setUp()
  {
    this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();

    this.mockRestServiceServer = MockRestServiceServer.createServer(this.clientCredRest);


  }
  @Test
  public void testRegistrationThatReturnsBadRequestWhenUserAlreadyExist()
  {




 this.mockRestServiceServer.expect(MockRestRequestMatchers.requestTo("localhost:8081/oauth/token")).andExpect(MockRestRequestMatchers.method(HttpMethod.POST))
    .andRespond(MockRestResponseCreators.withSuccess().contentType(MediaType.APPLICATION_JSON).body("{\n" +
            "\"access_token\": \"8ecd93d4-2484-46de-922a-652fa79d027d\",\n" +
            "\"token_type\": …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-security-oauth2

6
推荐指数
2
解决办法
1205
查看次数

Docker与ElasticSearch非root权限问题

我正在尝试通过 docker-compose up 在 Docker 上运行 ElasticSearch。每当我尝试启动容器时,都会收到此错误:

 Running as non-root...
 elasticsearch    | 2017-01-06 00:08:23,861 main ERROR Could not  register mbeans java.security.AccessControlException: access denied  ("javax.management.MBeanTrustPermission" "register")
  elasticsearch    |    at   java.security.AccessControlContext.checkPermission(AccessControlContext.jav       a:472)
  elasticsearch    |    at  java.lang.SecurityManager.checkPermission(SecurityManager.java:585)
  elasticsearch    |    at   com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.checkMBeanTrustPermission(DefaultMBeanServerInterceptor.java:1848)
  elasticsearch    |    at   com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(Default MBeanServerInterceptor.java:322)
   elasticsearch    |   at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)
  elasticsearch    |    at org.apache.logging.log4j.core.jmx.Server.register(Server.java:389)
  elasticsearch    |    at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:167)
  elasticsearch    |    at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:140)
  elasticsearch    |    at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:541)
   elasticsearch    |   at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:258)
  elasticsearch    |    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:206)
  elasticsearch    |    at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:220)
  elasticsearch    |    at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:197)
  elasticsearch …
Run Code Online (Sandbox Code Playgroud)

elasticsearch docker docker-compose

5
推荐指数
0
解决办法
1261
查看次数

错误:Mongo + Nodejs项目检测到循环依赖

美好的一天:

我目前正在研究NodeJs + MongoDB项目。我的解决方案很简单,我有3个集合(客户,范围,授权)。范围在“客户与赠款”集合之间形成了多对多关系。目前,我正在查询一个Client记录,然后获取分配给该Client的所有Scope集合,最后,最后获取我先前查询的Scope集合中的所有Grant记录。这是我的代码:

getClient (clientId, clientSecret, callback) {
 let that = this;
 this.mongoClient.collection('client').findOne({"client" : clientId, "client_secret" : clientSecret}, function (err, client) {
     if (err) {
         return callback(err, null);
     } 
     that.mongoClient.collection('scope').find({'client_id': client._id}, {"service_id":1}, function(err, serviceIds) {
         that.mongoClient.collection('grant').find({'_id': { $exists : true, $in : serviceIds }}, function(err, grants) { 
             console.log(grants.toArray());
             callback(err, client);
         })
     });


 });
}
Run Code Online (Sandbox Code Playgroud)

当我运行代码时,我得到的是:

Promise {


 <rejected> Error: cyclic dependency detected
    at serializeObject (/home/vagrant/api/node_modules/bson/lib/bson/parser/serializer.js:296:33)
    at serializeInto (/home/vagrant/api/node_modules/bson/lib/bson/parser/serializer.js:776:17)
    at …
Run Code Online (Sandbox Code Playgroud)

mongodb node.js

3
推荐指数
1
解决办法
2653
查看次数

无法检测测试类的默认资源位置:类路径资源不存在

我在詹金斯(Jenkins)中运行Maven build遇到了一个小问题。它正在尝试运行我的集成测试,但是,继续抛出此错误:

 java.lang.IllegalStateException: Neither GenericXmlContextLoader nor AnnotationConfigContextLoader was able to detect defaults, and no ApplicationContextInitializers were declared for context configuration [ContextConfigurationAttributes@2d10dd87 declaringClass = 'com.xxxx.api.services.MessageServiceImplIntegrationTest', locations = '{}', classes = '{}', inheritLocations = true, initializers = '{}', inheritInitializers = true, name = [null], contextLoaderClass = 'org.springframework.test.context.ContextLoader']
Run Code Online (Sandbox Code Playgroud)

有关完整的堆栈跟踪链接,请参见链接

java spring maven jenkins

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

属性'profile'不允许出现在元素'beans:bean'中

不知道这里发生了什么.我的XML bean定义架构正在使用:

 <?xml version="1.0" encoding="UTF-8"?>
 <beans:beans xmlns="http://www.springframework.org/schema/mvc"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:jpa="http://www.springframework.org/schema/data/jpa"
         xmlns:beans="http://www.springframework.org/schema/beans"
         xmlns:context="http://www.springframework.org/schema/context"
         xmlns:tx="http://www.springframework.org/schema/tx"
         xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/data/jpa
    http://www.springframework.org/schema/data/jpa/spring-jpa-1.1.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
Run Code Online (Sandbox Code Playgroud)

定义中有问题的bean:

 <beans:bean profile="dev,qa,prod">
        <beans:bean parent="propertyConfigurer">
            <beans:property name="order" value="0"></beans:property>
            <beans:property name="locations">
                <beans:list>
                    <beans:value>classpath:messages.properties</beans:value>
                     <beans:value>classpath:common.properties</beans:value>
                    <beans:value>classpath*:META-INF/properties/local.properties</beans:value>
                </beans:list>
            </beans:property>
        </beans:bean>
</beans:bean>
Run Code Online (Sandbox Code Playgroud)

但是,我得到了:

 cvc-complex-type.3.2.2: Attribute 'profile' is not allowed to appear in element 'beans:bean'
Run Code Online (Sandbox Code Playgroud)

有任何想法吗

java spring spring-mvc

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