小编gst*_*low的帖子

如何将异常的集合作为根本原因传递?

某种方法myMethod调用多个并行执行并等待其终止。

这些并行执行可以例外完成。因此myMethod获得一个例外列表。

我想将异常列表作为根本原因进行传递,但根本原因可能只是单个异常。当然,我可以创建自己的异常来实现所需的功能,但是我想知道Java,Spring或Spring Batch是否具有类似这样的功能。

java spring exception spring-batch

44
推荐指数
2
解决办法
1403
查看次数

如何在某些弹簧剖面中禁用飞路?

现在我有使用ms sql server的spring-boot应用程序.我们使用flyway fr迁移.

我想为测试添加额外的配置文件.我想从实体类生成表.并且不要使用飞路.

我试过smth在application.yaml中这样写

spring:
  profiles: test
  jpa:
      generate-ddl: true
      hibernate:
  datasource:
    url: jdbc:h2:mem:test_db;MODE=MSSQLServer
    username: sa
    password:
Run Code Online (Sandbox Code Playgroud)

但无论如何,flyway开始了

java spring flyway spring-profiles spring-boot

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

行家.-source 1.5不支持lambda表达式

我使用maven来构建我的项目.

我有以下配置:

D:\ freelance\polyndrom> mvn -verion Apache Maven 3.2.3(33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-12T00:58:1 0 + 04:00)Maven home:C:\ Program Files\apache\apache-maven-3.2. 3 Java版本:1.8.0_25,供应商:Oracle Corporation Java home:C:\ Program Files\Java\jdk1.8.0_25\jre默认语言环境:ru_RU,平台编码:Cp1251操作系统名称:"windows 7",版本:"6.1 ",arch:"amd64",家庭:"dos"

但是当我编译项目时,我看到以下错误:

lambda expressions are not supported in -source 1.5
Run Code Online (Sandbox Code Playgroud)

我很困惑 - 我看到我使用java 8.

pom.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>polyndrom</groupId>
    <artifactId>polyndrom</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.8.4</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>com.peterservice.polyndrom.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>           
        </plugins>
    </build>
</project>
Run Code Online (Sandbox Code Playgroud)

java lambda maven

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

可以春天@Autowired地图?

这是地图

@Autowired
private Map<String, ISendableConverter> converters;
Run Code Online (Sandbox Code Playgroud)

ISendableConverter

public interface ISendableConverter {

    ISendableMsg convert(BaseMessage baseMessage);

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

有几个类实现 ISendableConverter

我想converters通过使用spring Autowried 将它们注入变量.

类的实例作为值,方法的结果@Autowried作为键.

像这个

@Component
public class SendableVoiceMsgConverter implements ISendableConverter {

    @Override
    public ISendableMsg convert(BaseMessage baseMessage) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String getType() {
        return "VOICE";
    }
}
Run Code Online (Sandbox Code Playgroud)

这可能吗?如何?

java spring autowired

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

如何在Spring MVC中实现HTTP字节范围请求

我的网站上有视频倒带的问题.

我找出了http标题的问题.

我当前的控制器方法返回视频:

@RequestMapping(method = RequestMethod.GET, value = "/testVideo")
@ResponseBody
public FileSystemResource testVideo(Principal principal) throws IOException {
   return new FileSystemResource(new File("D:\\oceans.mp4"));
}
Run Code Online (Sandbox Code Playgroud)

如何用字节范围支持重写以下代码?

PS

我见过以下示例http://balusc.blogspot.in/2009/02/fileservlet-supporting-resume-and.html

但是这段代码看起来很难,我无法理解.我希望在春天mvc存在方式更简单.

java spring http spring-mvc video-streaming

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

由于cookie冲突(授权代码机制),官方Spring安全性oauth2示例不起作用

根据教程Spring Boot和OAuth2

我有以下项目结构:

在此输入图像描述

以下源代码:

SocialApplication.class:

@SpringBootApplication
@RestController
@EnableOAuth2Client
@EnableAuthorizationServer
@Order(200)
public class SocialApplication extends WebSecurityConfigurerAdapter {

    @Autowired
    OAuth2ClientContext oauth2ClientContext;

    @RequestMapping({ "/user", "/me" })
    public Map<String, String> user(Principal principal) {
        Map<String, String> map = new LinkedHashMap<>();
        map.put("name", principal.getName());
        return map;
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // @formatter:off
        http.antMatcher("/**").authorizeRequests().antMatchers("/", "/login**", "/webjars/**").permitAll().anyRequest()
                .authenticated().and().exceptionHandling()
                .authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/")).and().logout()
                .logoutSuccessUrl("/").permitAll().and().csrf()
                .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()).and()
                .addFilterBefore(ssoFilter(), BasicAuthenticationFilter.class);
        // @formatter:on
    }

    @Configuration
    @EnableResourceServer
    protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
        @Override
        public void configure(HttpSecurity http) throws Exception …
Run Code Online (Sandbox Code Playgroud)

java spring-security oauth-2.0 spring-oauth2

29
推荐指数
3
解决办法
3763
查看次数

为什么java.lang.Long的.longValue()将其(长)实例值强制转换为long?

我一直在调查java.lang.Long类源代码.

考虑一下:

public final class Long extends Number implements Comparable<Long> {
      ....
      private final long value;    
      ....
      public long longValue() {
            return (long)value;
      }
      ....
}
Run Code Online (Sandbox Code Playgroud)

什么是投理由longlong

为什么不在这种情况下将序列化(?)重新归类为Number类?

PS1 源代码链接

我有这些可能的解释:

  1. 开发人员粗心大意
  2. 符合一些统一的代码风格
  3. 它是为一些特殊情况而制作的,但我不明白为什么.

PS2

我的java版本 - 1.7.0_45-b18

PS3 仅供参考:

Integer:

public final class Integer extends Number implements Comparable<Integer> {
          ....
          private final int value;    
          ....
          public int intValue() {
            return value;
          }    
          ....
}
Run Code Online (Sandbox Code Playgroud)

Short:

public final class Short …
Run Code Online (Sandbox Code Playgroud)

java numbers long-integer

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

春天的安全.如何注销用户(撤销oauth2令牌)

当我想要注销时,我调用此代码:

request.getSession().invalidate();
SecurityContextHolder.getContext().setAuthentication(null);
Run Code Online (Sandbox Code Playgroud)

但在它之后(在使用旧的oauth令牌的下一个请求中)我调用

SecurityContextHolder.getContext().getAuthentication();

我在那里看到我的老用户

怎么解决?

java spring spring-security oauth-2.0

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

在Java中使用synchronized(Thread.currentThread()){...}的目的是什么?

我在项目中面对以下代码:

synchronized (Thread.currentThread()){
    //some code
}
Run Code Online (Sandbox Code Playgroud)

我不明白使用synchronized的原因currentThread.

两者之间有什么区别吗?

synchronized (Thread.currentThread()){
    //some code
}
Run Code Online (Sandbox Code Playgroud)

只是

//some code
Run Code Online (Sandbox Code Playgroud)

你能提供一个显示差异的例子吗?

UPDATE

更详细的代码如下:

synchronized (Thread.currentThread()) {
       Thread.currentThread().wait(timeInterval);
}
Run Code Online (Sandbox Code Playgroud)

看起来就像Thread.sleep(timeInterval).这是真的吗?

java concurrency multithreading synchronization thread-safety

25
推荐指数
3
解决办法
3206
查看次数

SecurityContext#setAuthentication是否保证可见性?

我在项目中使用spring security.

我有更改登录功能.为实现这一目标,我使用以下代码

Authentication authentication = ...
SecurityContextHolder.getContext().setAuthentication(authentication);
Run Code Online (Sandbox Code Playgroud)

但是现在我正在详细讨论这段代码并且看到认证字段不是volatile因此不能保证可见性:

 public class SecurityContextImpl implements SecurityContext {

    private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;

    // ~ Instance fields
    // ================================================================================================

    private Authentication authentication;
Run Code Online (Sandbox Code Playgroud)

我应该用自己的同步来包装我的代码以实现可见性吗?

PS

我已阅读/sf/answers/2154707901/

在单个会话中接收并发请求的应用程序中,将在线程之间共享相同的SecurityContext实例.即使正在使用ThreadLocal,它也是从HttpSession为每个线程检索的相同实例.如果您希望临时更改运行线程的上下文,则会产生影响.如果您只使用SecurityContextHolder.getContext(),并对返回的上下文对象调用setAuthentication(anAuthentication),则Authentication对象将在共享同一SecurityContext实例的所有并发线程中更改.您可以自定义SecurityContextPersistenceFilter的行为,为每个请求创建一个全新的SecurityContext,防止一个线程中的更改影响另一个线程.或者,您可以在临时更改上下文的位置创建新实例.SecurityContextHolder.createEmptyContext()方法始终返回新的上下文实例.

但我不明白春天如何保证能见度.刚写过会话中的每个线程都会看到变化.但没有答案有多快?更重要的是 - 没有解释可见性机制

java multithreading visibility spring-security thread-safety

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