我正在尝试使用Spring为webapp自动装配一些bean(用于依赖注入).一个控制器bean包含另一个bean,而另一个bean又拥有另一组bean的hashmap.目前,地图只有一个条目.当我在tomcat中运行并调用该服务时,我得到一个错误,说第二个bean(保存在控制器中)不是唯一的
No unique bean of type [com.hp.it.km.search.web.suggestion.SuggestionService] is defined: expected single matching bean but found 2: [suggestionService, SuggestionService]
Run Code Online (Sandbox Code Playgroud)
我无法看到我在两次定义bean的位置,但是我是Spring的新手并且自动装配,所以我可能会遗漏一些基本的东西.下面列出的xml和2类的源代码......
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.hp.it.km.search.web.suggestion" />
<mvc:annotation-driven />
<context:annotation-config />
<bean id="SuggestionController" class="com.hp.it.km.search.web.suggestion.SuggestionController">
<property name="service">
<ref bean="SuggestionService" />
</property>
</bean>
<bean id="SuggestionService" class="com.hp.it.km.search.web.suggestion.SuggestionService">
<property name="indexSearchers">
<map>
<entry key="KMSearcher"> <ref bean="KMSearcherBean"></ref></entry>
</map>
</property>
</bean>
<bean id="KMSearcherBean" class="com.hp.it.km.search.web.suggestion.SuggestionIndexSearcher">
<constructor-arg index="0" value="KMSearcher" />
<constructor-arg index="1" value="C://dev//workspace//search-restful-webapp//src//main//resources//indexes//keyword" />
</bean>
Run Code Online (Sandbox Code Playgroud)
带有自动控制器和服务bean的类asscoaites在这里......
@Controller
public class …
Run Code Online (Sandbox Code Playgroud) spring annotations dependency-injection spring-mvc autowired
我使用Spring Boot并希望使用Controller来接收多部分文件上传.发送文件时,我不断收到错误415不支持的内容类型响应,并且永远不会到达控制器
There was an unexpected error (type=Unsupported Media Type, status=415).
Content type 'multipart/form-data;boundary=----WebKitFormBoundary1KvzQ1rt2V1BBbb8' not supported
Run Code Online (Sandbox Code Playgroud)
我尝试使用form:action在html/jsp页面中发送,也在使用RestTemplate的独立客户端应用程序中发送.所有尝试都给出相同的结果
multipart/form-data;boundary=XXXXX not supported.
从多部分文档看来,必须将边界参数添加到分段上传,但这似乎与控制器接收不匹配 "multipart/form-data"
我的控制器方法设置如下
@RequestMapping(value = "/things", method = RequestMethod.POST, consumes = "multipart/form-data" ,
produces = { "application/json", "application/xml" })
public ResponseEntity<ThingRepresentation> submitThing(HttpServletRequest request,
@PathVariable("domain") String domainParam,
@RequestParam(value = "type") String thingTypeParam,
@RequestBody MultipartFile[] submissions) throws Exception
Run Code Online (Sandbox Code Playgroud)
使用Bean安装程序
@Bean
public MultipartConfigElement multipartConfigElement() {
return new MultipartConfigElement("");
}
@Bean
public MultipartResolver multipartResolver() {
org.springframework.web.multipart.commons.CommonsMultipartResolver multipartResolver = new org.springframework.web.multipart.commons.CommonsMultipartResolver();
multipartResolver.setMaxUploadSize(1000000);
return …
Run Code Online (Sandbox Code Playgroud) 我有一个简单的Dockerfile,但第一个RUN命令(将主机IP地址附加到/ etc/hosts)没有任何效果
FROM dockerfile/java
RUN sudo echo "XX.XX.XXX.XXX some.box.com MyFriendlyBoxName" >> /etc/hosts
ADD ./somejavaapp.jar /tmp/
#CMD java -jar /tmp/somejavaapp.jar
EXPOSE 8280
Run Code Online (Sandbox Code Playgroud)
我建立使用
docker build .
Run Code Online (Sandbox Code Playgroud)
然后测试RUN回波线是否有效
sudo docker run -t -i <built image ID> /bin/bash
Run Code Online (Sandbox Code Playgroud)
然后我进入容器但未附加/ etc/hosts文件.现在在容器中运行相同的echo ....行具有所需的效果
谁能告诉我我的dockerfile RUN有什么问题......?
因此,PDF压缩中存在一些线索,说压缩PDF有一些但不是很多,因为PDF已经被压缩了.
我的问题是:所有PDF格式都适用,包括格式的旧版本吗?
此外,我确信可能有人(可能是白痴)将位图放入PDF而不是JPEG等.我们的公司在其数据库中有很多PDF(可能有一些较旧的格式).我们正在考虑使用gzip在传输过程中进行压缩,但不知道它是否值得麻烦
我可以将/**通配符放在请求映射的中间,例如:"/ some/resource/**/somthing"
在Spring 3中,我可以做到这一点
@RequestMapping("/some/resource/**")
Run Code Online (Sandbox Code Playgroud)
来图
/some/resource/A -> ControllerMethod1
/some/resource/A/B -> ControllerMethod1
/some/resource/A/B/C/D/E/F -> ControllerMethod1
Run Code Online (Sandbox Code Playgroud)
对于任何数量的路径部分
但是这个映射太贪婪了,不允许我将子URL映射@RequestMapping("/some/resource/**/somthing")
到另一个控制器,例如
/some/resource/A/somthing -> ControllerMethod2
/some/resource/A/B/somthing -> ControllerMethod2
/some/resource/A/B/C/D/E/F/somthing -> ControllerMethod2
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我正在尝试让Maven为一些遗留代码调用ANT构建.ant构建通过ant正确构建.但是,当我使用maven ant插件调用它时,它失败并出现以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run (default) on project CoreServices: An Ant BuildException has occured: The following error occurred while executing this line:
[ERROR] C:\dev\projects\build\build.xml:158: The following error occurred while executing this line:
[ERROR] C:\dev\projects\build\build.xml:62: The following error occurred while executing this line:
[ERROR] C:\dev\projects\build\build.xml:33: The following error occurred while executing this line:
[ERROR] C:\dev\projects\ods\build.xml:41: Unable to find a javac compiler;
[ERROR] com.sun.tools.javac.Main is not on the classpath.
[ERROR] Perhaps JAVA_HOME does not point to the JDK.
[ERROR] …
Run Code Online (Sandbox Code Playgroud) 在我的ant构建id结束时,它调用等效的命令行调用
mvn install:install-file -Dfile=my.jar -DgroupId=com.company.project -DartifactId=my_project -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true
Run Code Online (Sandbox Code Playgroud)
这样它就会将新构建的jar添加到另一个项目依赖的maven资源库中.
我尝试使用maven-ant-task并将maven-ant-task jar添加到ant build项目中,并将以下代码添加到build.xml:
<target name ="minstall" depends="jar">
<artifact:pom id="maven_install" file="maven_install.xml" />
<artifact:install file="${out.dir}/my_project.jar">
<pom refid="maven_install"/>
</artifact:install>
</target>
Run Code Online (Sandbox Code Playgroud)
但似乎缺少一些东西,因为它不适合我.首先,我在build.xml(ant构建文件)中得到错误
元素"artifact:pom"的前缀"artifact"未绑定.
我究竟做错了什么.我对蚂蚁比较陌生?
在一个问题上,相关POM文件的目的是什么?我通常不会在这个项目中有一个POM,因为它是一个蚂蚁构建
我需要在 2 个或多个 android 应用程序之间共享一个通用的永久登录(身份验证令牌)。诀窍是不需要安装任何一个应用程序即可让另一个应用程序工作。它们彼此独立。
因此,在应用程序登录之前,它会询问“是否可能有另一个友好的应用程序可以给我(或已存储在某处)一个我可以使用的令牌?”
显然,我可以使用多种方法(和问题)来解决这个问题:
stackoverflow 的人认为什么是简单但又健壮的最佳方法?
在Android中运行标准junit测试(不是AndroidTestCase)时,如何获取src / test / resources中的资源中的资源?
我已经尝试了所有常见的...
getClass().getResourceAsStream("/testData.dat");
和...
Thread.currentThread().getContextClassLoader() .getResourceAsStream("/testData.dat");
还有 gradle 复制资源..
任务 copyTestResources(type: Copy) { from "${projectDir}/src/test/resources" into "${buildDir}/classes/test" }
让我困惑的是,当我在单元测试中询问类加载器路径是用于获取资源时
类加载器 classLoader = Thread.currentThread().getContextClassLoader(); URL资源 = classLoader.getResource(".");
它返回: /home/rob/Android/Sdk/platforms/android-17/data/res
谁能向我解释一下这一点,并告诉我如何在项目中的任何位置获得相对路径,以便我可以使用测试资源?
是否有任何简单的方法来分析源代码以列出没有任何javadocs的类的数量?
作为技术债务练习的一部分,我想列出所有这些文件,并在团队中分享列表,让原作者写出来.
注意:我们使用gradle作为构建系统
更新...所以默认情况下会创建空的javadocs,但是我们的开发人员已经充满了它们.我希望能够在类级别的doc中查看所有没有任何描述的类.我不太关心方法.
如何捕获(出于声明目的)传递给静态存根方法调用的参数?
methodBeingStubbed看起来像这样...
public class SomeStaticClass{
protected static String methodBeingStubbed(Properties props){
...
Run Code Online (Sandbox Code Playgroud)
我存根方法调用,因为它需要验证它是否被调用...
PowerMockito.stub(PowerMockito.method(SomeStaticClass.class, "methodBeingStubbed")).toReturn(null);
PowerMockito.verifyStatic();
Run Code Online (Sandbox Code Playgroud)
但是我现在也想知道什么属性传递给了这个“ methodBeingStubbed”,并断言它是预期的
在此图中,我想找到所有灰色节点在红色气泡中圈出,而不是任何其他灰色节点.也就是说所有带有label:OTHER的节点都是A和C之间路径上节点的子节点.NB A和C之间的路径可能比这里显示的3个节点长.
所以我想要做的是获得一个路径p = A ... C和子查询路径中的每个节点 - [:HAS] - >(n:OTHER)关系.
但是我坚持使用子查询,因为它不是在初始查询的结果集上,而是在所有节点上.
所以这给了我所有的灰色节点:(而不仅仅是红色泡泡中的节点.请帮忙
match p=(n:MAIN)-[:EXTENDS*]->(m:MAIN)
where n.name = 'A' AND m.name='C'
WITH nodes(p) AS collection
match (l:MAIN)-[:HAS]->(u:OTHER) return u; //This last part is my subquery
Run Code Online (Sandbox Code Playgroud) 我可以在运行时指定关系类型吗?
我正在使用类似的东西在实体中创建一组relationshipEntity对象
@Fetch
@RelatedToVia(type="RELATED_IN_SOME_WAY", direction = Direction.BOTH)
Set<ThingRelationship> relationships = new HashSet<ThingRelationship>();
Run Code Online (Sandbox Code Playgroud)
ThingRelationship是哪里
@RelationshipEntity
public class ThingRelationship {
public ThingRelationship() {
super();
}
//incremental neo4j set ID
@GraphId Long nodeId;
//Start and end nodes
@StartNode Thing startThing;
@EndNode Thing endThing;
//Relationship Type
@org.springframework.data.neo4j.annotation.RelationshipType
String relationship;
Run Code Online (Sandbox Code Playgroud)
但是我不想在编译时指定关系类型(type ="RELATED_IN_SOME_WAY"),而是在运行时指定.当我删除type ="RELATED_IN_SOME_WAY时,我收到一个必须定义默认类型的错误
在Neo4j这样的运行时关系类型我认为需要使用DynamicRelationshipType但是我不认为Spring Data Neo4j支持这个概念.
我是否正确,如果是这样,那么这个问题呢?我是否需要转储Spring Data Neo4j并转而使用Core API?
java ×6
spring ×3
spring-mvc ×3
android ×2
junit ×2
maven ×2
neo4j ×2
annotations ×1
ant ×1
autowired ×1
compression ×1
cypher ×1
docker ×1
dockerfile ×1
gzip ×1
jar ×1
javadoc ×1
maven-2 ×1
maven-plugin ×1
mockito ×1
multipart ×1
pdf ×1
powermock ×1
resources ×1
spring-boot ×1
stubbing ×1
url ×1