小编ari*_*iro的帖子

注入自动连接的依赖项失败;

我正在开发一个小型Java EE Hibernate Spring应用程序,并出现错误:
Error creating bean with name 'articleControleur': Injection of autowired dependencies failed;

oct. 26, 2011 3:51:44 PM org.apache.catalina.core.ApplicationContext log
Grave: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'articleControleur': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.bd.service.ArticleService com.bd.controleur.ArticleControleur.articleService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.bd.service.ArticleService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
at …
Run Code Online (Sandbox Code Playgroud)

spring autowired

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

java集合 - mapset中的keyset()vs entrySet()

我把一个字符串数组元素是一个映射,其中字符串数组的元素是键,字的频率是值,例如:

String[] args = {"if","it","is","to","be","it","is","up","me","to","delegate"};
Run Code Online (Sandbox Code Playgroud)

然后地图会有像这样的条目 [ if:1, it:2 .... ]

Set<String> keys = m.keySet();
System.out.println("keyset of the map : "+keys);
Run Code Online (Sandbox Code Playgroud)

打印所有键: "if","it","is","to","be","it","is","up","me","to","delegate"

Set<Map.Entry<String, Integer>> entrySet = m.entrySet();
Iterator<Map.Entry<String, Integer>> i = entrySet.iterator();
while(i.hasNext()){
    Map.Entry<String, Integer> element = i.next();
    System.out.println("Key: "+element.getKey()+" ,value: "+element.getValue());
}
Run Code Online (Sandbox Code Playgroud)

打印所有键值对:

使用条目集打印所有值:

Key: if ,value: 1
Key: it ,value: 2
Key: is ,value: 2
Key: to ,value: 2
Key: be ,value: 1
Key: up ,value: 1
Key: me ,value: 1
Key: delegate ,value: 1
Run Code Online (Sandbox Code Playgroud)

但是下面的代码块应该打印与上面完全相同的输出,但它不会:

Iterator<String> …
Run Code Online (Sandbox Code Playgroud)

java collections hashmap linkedhashmap keyset

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

动态加载反应组分

我需要动态加载react组件.

我得到要从用户加载为字符串的组件的名称.我正在使用webpack.

如何动态加载组件而不是静态导入语句.似乎Require.Ensure不评估表达式.我想要实现的是这样的.

require.ensure([ "./widgets/" + componentName ] ,(require) => {
    let Component = require("./widgets/" + componentName);   
});
Run Code Online (Sandbox Code Playgroud)

但这似乎不起作用.

reactjs webpack

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

尝试使用EF更新实体并使用WCF发送它 - 属性在更新方案中导致异常

我正在尝试使用WCF发送对象.使用EF从DB检索对象.

这是我得到的例外:

在此输入图像描述

这仅在更新方案中发生.插入效果很好.
跟踪错误,我发现问题出在Travelers我最近添加的一个集合(称为).

以下是在WCF发送更新后的实体之前,在更新之后尝试在运行时观察其值时发生的情况:

在此输入图像描述

这是违规类的属性声明(我尝试取消注释DataMember属性,但它不起作用):

[DataContract]
public class Travel : InsuredObject, ISaleEntity, ICloneable
{    
    //[DataMember]
    public virtual ICollection<Traveler> Travelers { get; set; } 
    ...  
Run Code Online (Sandbox Code Playgroud)

我已经读过这个this.Configuration.ProxyCreationEnabled = false;和/或this.Configuration.LazyLoadingEnabled = false;可能会修复它,但我不能因为我以外的原因而改变它们,即使我尝试使用它们 - 我还有其他一些例外......

附加代码:
更新方法:

public virtual TEntity CreateAndUpdate(int saleId, TEntity entity) {
    var context = ((IObjectContextAdapter)this.Context).ObjectContext;

    var objBaseSet = context.CreateObjectSet<TBase>();

    var entityBaseKey = context.CreateEntityKey(objBaseSet.EntitySet.Name, entity);
    Object foundBaseEntity;
    var baseExists = context.TryGetObjectByKey(entityBaseKey, out foundBaseEntity);

    entity.Id = saleId;

    if (!baseExists) {
        this.GetDbSet<TEntity>().Add(entity); 
    }

    this.objectContext.SaveChanges(); …
Run Code Online (Sandbox Code Playgroud)

c# wcf entity-framework-5

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

在JPA中选择具有1个条件的每个用户的最近日期的行

我有这个实体,我想为每个设备列出属性message = 1的最后一个事件

@Entity
@Table(name = "t_device_event")
@NamedQueries(value = { 
@NamedQuery(name = "DeviceEvent.findWithMessageActive",
            query = "from DeviceEvent as de1 where de1.message = 1 and de1.received = " 
                  + " ( select max(de2.received) from DeviceEvent de2 " 
                  + " where de2.device.id = de1.device.id )  "), )
public class DeviceEvent {
     ..
}
Run Code Online (Sandbox Code Playgroud)

但是在最后一次测试中我有一个断言问题,因为它认为device3是最后一个事件,而不是这种情况.

assertTrue ((numDevicesWithActiveMessage+1) == deviceEventService.findWithActiveMessage().size());

DeviceEvent deviceEvent3 = newDeviceEvent();
deviceEvent3.setMessage(1);
deviceEventService.save(deviceEvent3);

DeviceEvent deviceEvent4 = newDeviceEvent();
deviceEventService.save(deviceEvent4);

assertTrue ((numDevicesWithActiveMessage+1) == deviceEventService.findWithActiveMessage().size());
Run Code Online (Sandbox Code Playgroud)

java sql junit mysqli jpa

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

模拟或构建Jersey InboundJaxrsResponse

我是一个相当新的开发球衣客户端,并在一些测试中遇到了一些问题.首先,我可能应该提到我的应用程序是所有客户端,没有服务器端的东西.

我的问题是我想创建一个Response实例的对象InboundJaxrsResponse,到目前为止,我试图通过模拟Response使用Mockito和实现这一点ResponseBuilder.build()

使用Mockito:

Response response = mock(Response.class);
when(response.readEntity(InputStream.class))
    .thenReturn(ClassLoader.getSystemResourceAsStream("example_response.xml");
Run Code Online (Sandbox Code Playgroud)

这工作正常,当我读出响应的实体时,response.readEntity(InputStream.class) 我得到了预期的实体.但是我需要多次从响应中读取实体.为了实现这一点,我response.bufferEntity()在读出实体之前使用.我第一次阅读实体一切正常,但第二次我得到一个异常I/O stream closed......好吧我想出了嘲笑方法bufferEntity,如下所示:

Response response = mock(Response.class);
when(response.bufferEntity()).thenCallRealMethod();
when(response.readEntity(InputStream.class))
    .thenReturn(ClassLoader.getSystemResourceAsStream("example_response.xml");
Run Code Online (Sandbox Code Playgroud)

但这只是导致错误被调用时抛出bufferEntity(),这是因为bufferEntity()Responseabstract.

我的另一个尝试是通过使用ResponseBuilder.build()如下:

ResponseBuilder responseBuilder = Response.accepted(ClassLoader.getSystemResourceAsStream("example_response.xml"));
Response response = responseBuilder.build();
Run Code Online (Sandbox Code Playgroud)

这个声明很好,通过调试我的响应我可以看到它有正确的实体等等.但是这次当我打电话的时候,我response.bufferEntity()得到一个异常抛出,说这个操作是非法的,OutboundJaxrsResponse所以通过这种方式构建响应会导致错误的实例Response.class:

所以最终有三个问题.

  1. 这是否可以模拟/构建此类型的对象进行测试?
  2. 有没有办法模拟入站响应?
  3. 有没有一种办法,而不是创建的实例OutboundJaxrsResponseResponseBuilder.build()创建的实例InboundJaxrsResponse,或至少铸造/实例转换OutboundJaxrsResponse到的实例OutboundJaxrsResponse

java unit-testing jersey jersey-client java-ee-7

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

Http 415 on file使用jersey上传

我的RESTful文件上传代码:

@Path("/upload") 
@POST 
@Consumes("multipart/form-data") 
public String post(
    @FormDataParam("part") String s, 
    @FormDataParam("part") FormDataContentDisposition d) { 
    return s + ":" + d.getFileName(); 
}
Run Code Online (Sandbox Code Playgroud)

当我尝试使用curl curl -X POST --form part=@file.txt url上传文件时

我收到HTTP 415不支持的媒体类型错误.怎么了 ?

java jsp file-upload jersey

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

EJBCLIENT000025:没有EJB接收器可供处理?

我试图从可执行的Java应用程序(本地不在JBoss上)连接到本地JBoss 7.2上的远程EJB.

但是我收到以下错误/异常:

java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:xx-xx, moduleName:xx-xx-business-impl, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@14bc02d
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:693)
    at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
    at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:183)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:177)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:161)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:124)
    at com.sun.proxy.$Proxy0.getX(Unknown Source)
    at com...ris.client.PACSServiceTest.main(PACSServiceTest.java:71)
Run Code Online (Sandbox Code Playgroud)

测试远程bean TestService及其实现在EAR中.

服务器类:

@Remote
public interface TestService {

    public int getX();

}

@Stateless
@Remote(TestService.class)
public class TestServiceBean implements TestService{

    @Override
    public int getX() {
        // TODO Auto-generated method stub
        return 1111;
    }
}
Run Code Online (Sandbox Code Playgroud)

客户代码:

final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, …
Run Code Online (Sandbox Code Playgroud)

ejb rmi remoteobject java-ee jboss7.x

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

将 Cordova 离子项目导入 Android Studio?

我正在尝试在 Android Studio 中导入 Cordova Ionic 项目以修改一些内容并尝试解决一些错误,但我不能。

我以前从未使用过 Ionic,我尝试遵循一些有关如何将 Ionic 导入 Android 的教程,但没有人为我工作。

在所有这些中,您必须转到Android Studio > 导入项目(Eclipse ADT、Gradle 等),然后选择一个名为 platform 的文件夹,然后选择 Android Gradle。

但问题是在我的项目中我只有这个文件夹:hooks、css、www。

eclipse import android cordova ionic-framework

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

JNDI 没有可用于处理的 EJB 接收器

我的 EJBTest 有问题。

我已经安装了WildFly并配置了用户管理和应用程序管理。

我编写了一个 EJB 3.0 并部署了它:

@Stateless
@Remote(NewSessionBeanRemote.class)
public class NewSessionBean implements NewSessionBeanRemote {

    List<String> bookShielf;

    /**
     * Default constructor. 
     */
    public NewSessionBean() {
        bookShielf = new ArrayList<String>();
    }

    @Override
    public void addBook(String bookName) {
        bookShielf.add(bookName);
    }

    @Override
    public List getBook() {
        return bookShielf;
    }
}
Run Code Online (Sandbox Code Playgroud)

后来我写了一个简单的客户端来连接它:

private static void invokeStatelessBean() throws NamingException {
    // Let's lookup the remote stateless calculator
    NewSessionBeanRemote remoteEjb = lookupRemoteSessionBean();
    System.out.println("Obtained a remote stateless calculator for invocation");
    String bookName = "TEST book";
    remoteEjb.addBook(bookName); …
Run Code Online (Sandbox Code Playgroud)

java error-handling ejb jndi wildfly-10

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

Eclipse 运行时安装配置目录中的 Jboss 6

我有一个正在处理的现有 JBoss 项目。

目前,每次我进行更改时,甚至是对 JSP 文件进行更改时,我都必须运行 ANT 构建来创建 EAR 文件,然后将文件导入到我从命令行启动的 JBoss localhost 中。

我想在 Eclipse 中运行 JBoss 以使开发更容易。

我已经从 Eclipse 的 Marketplace 安装了 JBoss Tools。但是,当我尝试安装运行时环境时,我无法通过配置屏幕。即使我将配置目录指向我的 standalone.xml 目录。

这是我无法通过的屏幕图片

有任何想法吗?

jboss

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

spring.jackson.default-property-inclusion 被忽略

在我的 Spring Boot/Kotlin 项目中,我试图让 JSON 转换器忽略其余控制器响应中的空值。

我尝试在 application.yml 中设置以下内容:

spring:
    jackson:
        default-property-inclusion: non_null
Run Code Online (Sandbox Code Playgroud)

我还尝试提供 of@Bean类型Jackson2ObjectMapperBuilder@ObjectMapper配置为.serializationInclusion(JsonInclude.Include.NON_NULL),但它仍然序列化所有空属性。

使用 Spring Boot 2.3.0、Kotlin 1.3.72、AdoptOpenJDK 13

jackson kotlin spring-boot spring-autoconfiguration

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

Java 从基类创建 devirt 类

假设我有一个基类:

Class A {
    public String field1;

    public A(String field1){
        this.field1 = field1;
    }
}
Run Code Online (Sandbox Code Playgroud)

和一个 devired 类:

Class B extends A {
    public String field2;
}
Run Code Online (Sandbox Code Playgroud)

假设我有一个List<A> listA,如何创建一个构造函数以便我可以轻松地将这个列表转换为List<B> listB?我想要有一个构造函数,B class它将获取并填充其中A object的所有字段,并具有一些逻辑来构造新字段。像这样的东西:AB

Class B extends A {
    public String field2;

    public B (A a){
        this = a;
        this.field2 = doLogic(a);
    }
}
Run Code Online (Sandbox Code Playgroud)

或者至少填写 B 中 A 的所有字段:

public B(A a){
    this = a;
}
Run Code Online (Sandbox Code Playgroud)

所以稍后我可以手动将 , 字段设置B为如下所示:

listA.stream().map(x …
Run Code Online (Sandbox Code Playgroud)

java oop inheritance constructor

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