我正在开发一个小型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) 我把一个字符串数组元素是一个映射,其中字符串数组的元素是键,字的频率是值,例如:
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) 我需要动态加载react组件.
我得到要从用户加载为字符串的组件的名称.我正在使用webpack.
如何动态加载组件而不是静态导入语句.似乎Require.Ensure不评估表达式.我想要实现的是这样的.
require.ensure([ "./widgets/" + componentName ] ,(require) => {
let Component = require("./widgets/" + componentName);
});
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用.
我正在尝试使用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) 我有这个实体,我想为每个设备列出属性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) 我是一个相当新的开发球衣客户端,并在一些测试中遇到了一些问题.首先,我可能应该提到我的应用程序是所有客户端,没有服务器端的东西.
我的问题是我想创建一个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()的Response是abstract.
我的另一个尝试是通过使用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:
所以最终有三个问题.
OutboundJaxrsResponse与ResponseBuilder.build()创建的实例InboundJaxrsResponse,或至少铸造/实例转换OutboundJaxrsResponse到的实例OutboundJaxrsResponse?我的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应用程序(本地不在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) 我正在尝试在 Android Studio 中导入 Cordova Ionic 项目以修改一些内容并尝试解决一些错误,但我不能。
我以前从未使用过 Ionic,我尝试遵循一些有关如何将 Ionic 导入 Android 的教程,但没有人为我工作。
在所有这些中,您必须转到Android Studio > 导入项目(Eclipse ADT、Gradle 等),然后选择一个名为 platform 的文件夹,然后选择 Android Gradle。
但问题是在我的项目中我只有这个文件夹:hooks、css、www。
我的 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) 我有一个正在处理的现有 JBoss 项目。
目前,每次我进行更改时,甚至是对 JSP 文件进行更改时,我都必须运行 ANT 构建来创建 EAR 文件,然后将文件导入到我从命令行启动的 JBoss localhost 中。
我想在 Eclipse 中运行 JBoss 以使开发更容易。
我已经从 Eclipse 的 Marketplace 安装了 JBoss Tools。但是,当我尝试安装运行时环境时,我无法通过配置屏幕。即使我将配置目录指向我的 standalone.xml 目录。
有任何想法吗?
在我的 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
假设我有一个基类:
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 ×6
ejb ×2
jersey ×2
android ×1
autowired ×1
c# ×1
collections ×1
constructor ×1
cordova ×1
eclipse ×1
file-upload ×1
hashmap ×1
import ×1
inheritance ×1
jackson ×1
java-ee ×1
java-ee-7 ×1
jboss ×1
jboss7.x ×1
jndi ×1
jpa ×1
jsp ×1
junit ×1
keyset ×1
kotlin ×1
mysqli ×1
oop ×1
reactjs ×1
remoteobject ×1
rmi ×1
spring ×1
spring-boot ×1
sql ×1
unit-testing ×1
wcf ×1
webpack ×1
wildfly-10 ×1