我正在尝试在子上下文中使用spring安全上下文,因此我可以在servlet上下文文件中使用url安全性.
我有:
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/spring-security.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>myapp-soap</servlet-name>
<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
<init-param>
<param-name>transformWsdlLocations</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
Run Code Online (Sandbox Code Playgroud)
在web.xml上,spring-security.xml上的一般安全配置和
<!-- Authorization configurations -->
<security:http auto-config="false" use-expressions="true"
create-session="never"
authentication-manager-ref="authenticationManager"
entry-point-ref="authenticationEntryPoint">
<security:custom-filter
position="PRE_AUTH_FILTER" ref="serviceAuthenticationFilter"/>
<security:intercept-url
pattern="/GetForbiddenUrl" access="hasRole('roleThatDoesntExist')" />
<security:intercept-url pattern="/**" access="permitAll" />
</security:http>
<!-- annotation security -->
<security:global-method-security pre-post-annotations="enabled"/>
Run Code Online (Sandbox Code Playgroud)
在myapp-soap-servlet.xml上.它不起作用但失败了
ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/my-app/v1/soap]] (ServerService Thread Pool -- 192) JBWEB000284: Exception starting filter springSecurityFilterChain:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined
Run Code Online (Sandbox Code Playgroud)
但是,如果我将<security:http>部分移动到spring-security root …
长期以来,Spring 一直推荐使用RestTemplate来同步 http 请求。然而,现在的文档说:
注意:从 5.0 开始,此类处于维护模式,仅接受较小的更改请求和错误。请考虑使用 org.springframework.web.reactive.client.WebClient ,它具有更现代的 API 并支持同步、异步和流场景。
但我还没有看到如何建议使用WebClient进行同步场景。文档中有这样的内容:
WebClient 可以通过在结果结束时阻塞来以同步方式使用
我已经看到一些代码库到处都使用 .block() 。然而,我的问题是,凭借一些反应式框架的经验,我逐渐明白阻止反应式调用是一种代码味道,实际上应该只在测试中使用。例如这个页面说
有时,您只能将部分代码迁移为响应式,并且需要在更多命令式代码中重用响应式序列。
因此,如果您需要阻塞直到 Mono 的值可用,请使用 Mono#block() 方法。如果 onError 事件被触发,它将抛出异常。
请注意,您应该通过尽可能支持端到端的反应式代码来避免这种情况。您必须在其他反应式代码中间不惜一切代价避免这种情况,因为这有可能锁定整个反应式管道。
那么我是否错过了一些可以避免 block() 但允许您进行同步调用的东西,或者是否在任何地方都使用 block() 真的是这样?
或者 WebClient API 的意图是暗示人们不应该再在代码库中的任何地方进行阻塞?由于 WebClient 似乎是 Spring 提供的未来 http 调用的唯一替代方案,因此未来在整个代码库中使用非阻塞调用并更改代码库的其余部分以适应这一点是唯一可行的选择吗?
这里有一个相关的问题,但它只关注发生的异常,而我有兴趣听到一般的方法应该是什么。
我试图解压缩文件(从FTP服务器检索):
ZipInputStream zis = new ZipInputStream(
new FileInputStream(zipFile));
ZipEntry ze = zis.getNextEntry();
while (ze != null) {
String fileName = ze.getName();
File newFile = new File(outputFileName+outputFolder + File.separator + fileName);
System.out.println("file unzip : " + newFile.getAbsoluteFile());
FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
sendFile = newFile;
ze = zis.getNextEntry();
}
zis.closeEntry();
zis.close();
System.out.println("Done");
Run Code Online (Sandbox Code Playgroud)
我在.zip文件中只有一个文本文件.此代码在我的本地Windows机器上正常工作.但是,当部署到ubuntu服务器上时,它会抛出以下异常.
java.util.zip.ZipException: invalid entry size (expected 193144 but got 193138 bytes)
at java.util.zip.ZipInputStream.readEnd(ZipInputStream.java:386)
at java.util.zip.ZipInputStream.read(ZipInputStream.java:156) …Run Code Online (Sandbox Code Playgroud) Java HashMap实现在Entry私有类中具有"下一个"成员.因为,键的新值将覆盖旧值,在Entry类中使用"next"成员是什么.
static class Entry<K,V> implements Map.Entry<K,V> {
final K key;
V value;
Entry<K,V> next;
final int hash;
/**
* Creates new entry.
*/
Entry(int h, K k, V v, Entry<K,V> n) {
value = v;
next = n;
key = k;
hash = h;
}
.....
}
Run Code Online (Sandbox Code Playgroud) 我在父pom中有一个dependencyManagement部分
<dependencyManagement>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.1</version>
</dependency>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)
拥有它的孩子pom
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.0</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
我试图使用enforcer插件来防止这种覆盖在poms中,允许这些仅在父设置中设置,但是无法设置.我希望这会使构建失败.这可能,使用该插件或其他方式?
有DependencyCovergence,它强制所有版本都是相同的,但这太严格了,因为我不想控制所有传递依赖 - 只是明确定义的那些.
如果我可以防止在子pom中引入任何新的依赖关系,我会很高兴 - 所有定义的内容应该在父pom中定义,然后在子代中提到,如果需要的话.
怎样POST方法不支持Spring Boot MVC?我正在尝试实现一个接受实体列表的简单post方法:这是我的代码
@RestController(value="/backoffice/tags")
public class TagsController {
@RequestMapping(value = "/add", method = RequestMethod.POST)
public void add(@RequestBody List<Tag> keywords) {
tagsService.add(keywords);
}
}
Run Code Online (Sandbox Code Playgroud)
点击此URL如下:
http://localhost:8090/backoffice/tags/add
Run Code Online (Sandbox Code Playgroud)
请求机构:
[{"tagName":"qweqwe"},{"tagName":"zxczxczx"}]
Run Code Online (Sandbox Code Playgroud)
我收到:
{
"timestamp": 1441800482010,
"status": 405,
"error": "Method Not Allowed",
"exception": "org.springframework.web.HttpRequestMethodNotSupportedException",
"message": "Request method 'POST' not supported",
"path": "/backoffice/tags/add"
}
Run Code Online (Sandbox Code Playgroud)
编辑:
调试Spring Web Request Handler
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.checkRequest(request);
protected final void checkRequest(HttpServletRequest request) throws ServletException {
String method = request.getMethod();
if(this.supportedMethods != null …Run Code Online (Sandbox Code Playgroud) 我有一个java应用程序和postgresql数据库,以便在Heroku上运行它.我可以推送我的应用程序,但DB内容怎么样?我从数据库导出了一个完整的转储,但我不知道如何导入它.
通过谷歌搜索,你可以找到关于db:push这是一个有限的rubygem,而不是推动所需的所有东西.我有序列,bigint数据类型等.我也尝试导入使用heroku pg:psql --app MYAPP < db_all.out它只是连接和停止,并转到heroku pg:psql --app MYAPP并发出\i db_all.out有关权限的投诉.
我该怎么办?
首先,我不知道它是否被称为单元测试.如果它有不同的名称,请随时纠正我.
我正在开发像这样的Web应用程序.
假设我正在开发一个表单来将值保存到数据库中.我开发HTML和PHP.我有时间在浏览器中按F5并检查HTML/jQuery是否没有错误,PHP不会出现错误的分号等错误.
当它完成并且一切都准备好进行测试时,我开始测试我的代码的一小部分.喜欢;
如果它使用正确的值,并且失败并返回错误的值; 我相信表单按预期工作,没有错误,所以我转向其他事情.
而不是这样做,我想确保事情完美无缺,否则在没有垃圾邮件F5浏览器的情况下通知我这个问题.
像这样;
<?php
/* Unit Testing Start --
-ensure: isset($_POST['submit']) returns TRUE;
-ensure: isset($email) returns TRUE;
-ensure: isValidEmail($email) returns TRUE;
-ensure: connectDatabase() returns TRUE;
-ensure: getMysqlAffectedRows() returns 1;
-ensure: hasErrors() returns false;
*/
?>
Run Code Online (Sandbox Code Playgroud)
我的表单代码使用我上面发布的功能.
当它运行时,它应该向我显示如下消息:(最好还记录它)
Test complete. Tested (6) possibilities, (4) succeeded, (2) failed.
Failed 1: isValidEmail() returned FALSE, expected: TRUE.
Failed 2: getMysqlAffectedRows returned NULL/0, expected …Run Code Online (Sandbox Code Playgroud) 我试图构建 Maven 项目,
每当我在命令行上运行“mvn clean install”时,都会出现以下错误:
无法解析项目 com.my_project:jar:0.0.1-SNAPSHOT 的依赖项:无法收集 [com.datastax.cassandra:cassandra-driver-core:jar:3.0.1 (compile), org.apache.kafka 的依赖项:kafka-clients:jar:0.9.0.1(编译)、org.apache.kafka:kafka_2.10:jar:0.9.0.1(编译)、com.thinkaurelius.titan:titan-core:jar:1.0.0(编译) ), com.tinkerpop.blueprints:blueprints-core:jar:2.6.0 (编译), com.thinkaurelius.titan:titan-cassandra:jar:1.0.0 (编译), com.thinkaurelius.titan:titan-all: jar:1.0.0(编译)、org.aspectj:aspectjrt:jar:1.6.5(编译)、com.jayway.awaitility:awaitility:jar:1.6.5(编译)、junit:junit:jar:4.11(测试)]:无法读取 commons-codec:commons-codec:jar:1.4 的工件描述符:无法从/向中央传输工件 commons-codec:commons-codec:pom:1.4 (http://repo.maven.apache.org/maven2):拒绝访问:http : //repo.maven.apache.org/maven2/commons-codec/commons-codec/1.4/commons-codec-1.4.pom , 理由:禁止。-> [帮助 1]
请帮助我,我是 JAVA 世界的新手。
这是我拒绝访问的某种代理设置吗?
java ×4
spring ×3
maven ×2
frameworks ×1
hashmap ×1
heroku ×1
jboss7.x ×1
maven-3 ×1
mocking ×1
php ×1
postgresql ×1
reactive ×1
spring-boot ×1
spring-ws ×1
synchronous ×1
testing ×1
unit-testing ×1
unzip ×1
zip ×1