小编en *_*ris的帖子

在SpringBoot 2.0.1.RELEASE应用程序中读取文件

我有一个SpringBoot 2.0.1.RELEASE mvc应用程序.在资源文件夹中,我有一个名为/ elcordelaciutat的文件夹.

在控制器中我有这个方法来读取文件夹中的所有文件

ClassLoader classLoader = this.getClass().getClassLoader();
        Path configFilePath = Paths.get(classLoader.getResource("elcordelaciutat").toURI());    

        List<String> cintaFileNames = Files.walk(configFilePath)
         .filter(s -> s.toString().endsWith(".txt"))
         .map(p -> p.subpath(8, 9).toString().toUpperCase() + " / " + p.getFileName().toString())
         .sorted()
         .collect(toList());

        return cintaFileNames;
Run Code Online (Sandbox Code Playgroud)

运行应用程序.来自Eclipse工作正常,但是当我在Windows Server中运行应用程序时出现此错误:

java.nio.file.FileSystemNotFoundException: null
    at com.sun.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:171)
    at com.sun.nio.zipfs.ZipFileSystemProvider.getPath(ZipFileSystemProvider.java:157)
    at java.nio.file.Paths.get(Unknown Source)
    at 
Run Code Online (Sandbox Code Playgroud)

我解压缩生成的jar文件,文件夹就在那里!

和文件夹的结构是

elcordelaciutat/folder1/*.txt
elcordelaciutat/folder2/*.txt
elcordelaciutat/folder3/*.txt
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc java.nio.file spring-boot

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

AuthenticationManagerBuilder in SpringBoot 2.0.1.RELEASE

I have a SpringBoot 2.0.1.RELEASE mvc application, so in the security config I've defined this method:

@Autowired
 public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
            auth
                    .inMemoryAuthentication()
                    .withUser(User
                            .withDefaultPasswordEncoder()
                            .username(DEV_USER)
                            .password(DEV_PWD)
                            .roles("ADMIN").build());
        }
Run Code Online (Sandbox Code Playgroud)

but It seems that The method withDefaultPasswordEncoder() from the type User is deprecated but I don't know which I have to use instead,

spring spring-mvc spring-security password-encryption spring-boot

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

BCryptPasswordEncoder - 编码密码看起来不像 BCrypt

我有一个 SpringBoot 2.0.1.RELEASE mvc 应用程序,这是我的配置文件

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {


    @Autowired
    private Environment env;


    @Override
    protected void configure(HttpSecurity http) throws Exception {

        final List<String> activeProfiles = Arrays.asList(env.getActiveProfiles());
        if (activeProfiles.contains("dev")) {
            http.csrf().disable();
            http.headers().frameOptions().disable();
        }

        http
                .authorizeRequests()
                .antMatchers(publicMatchers()).permitAll()
                .and()
                .formLogin().loginPage("/login").defaultSuccessUrl("/elcordelaciutat/config")
                .failureUrl("/login?error").permitAll()
                .and()
                .logout().permitAll();
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {

         PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
         UserDetails userDetails = User.withUsername("elcor")
                  .password(encoder.encode("elcor"))
                  .roles("ADMIN")
                  .build();
         auth.inMemoryAuthentication().withUser(userDetails);

    }


    private String[] publicMatchers() {

         /** Public URLs. */
        final String[] PUBLIC_MATCHERS = {
                "/webjars/**", …
Run Code Online (Sandbox Code Playgroud)

spring spring-mvc spring-security bcrypt spring-boot

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

Java8列表.调用void函数

我在我的控制器中有以下代码片段,从第一个列表中我得到了所有用户,然后我迭代向他们发送电子邮件.不知何故,在函数中sendEmail()我不得不返回一个对象,但我不需要返回任何东西.

List<User> users = new ArrayList<User>();

menuPriceSummaryService.findAll()
    .stream()
    .map (mps -> checkPreferences(mps))
    .iterator()
    .forEachRemaining(users::addAll);

users
    .stream()
    .map (o -> sendEmail(o))
    .iterator();
Run Code Online (Sandbox Code Playgroud)

java collections lambda java-8 java-stream

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

insert varbinary value from hex literal in Microsoft SQL Server

I have a SpringBoot app, where I use jdbcTemplate to insert a row to a mssql

int numOfRowsAffected = remoteJdbcTemplate.update("insert into dbo.[ELCOR Resource Time Registr_]  "
                + "( [Entry No_], [Record ID], [Posting Date], [Resource No_], [Job No_], [Work Type], [Quantity], [Unit of Measure], [Description], [Company Name], [Created Date-Time], [Status] ) "
                + " VALUES (?,CONVERT(varbinary,?),?,?,?,?,?,?,?,?,?,?);",

                ELCORResourceTimeRegistr.getEntryNo(), 
                ELCORResourceTimeRegistr.getEntryNo()), 
                ELCORResourceTimeRegistr.getPostingDate(),
                ELCORResourceTimeRegistr.getResourceNo(), 
                jobNo,
                ELCORResourceTimeRegistr.getWorkType(), 
                ELCORResourceTimeRegistr.getQuantity(),
                ELCORResourceTimeRegistr.getUnitOfMeasure(), 
                ELCORResourceTimeRegistr.getDescription(),
                ELCORResourceTimeRegistr.getCompanyName(), 
                ELCORResourceTimeRegistr.getCreatedDate(), 
                0);
Run Code Online (Sandbox Code Playgroud)

the value of ELCORResourceTimeRegistr.getEntryNo() is a String with the value 0x00173672

but …

sql-server jdbc spring-jdbc jdbctemplate mssql-jdbc

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

RestTemplate:返回实体列表

有一个RestFull方法,它返回Menu对象的List

public ResponseEntity<List<Menu>> getMenus() {
..
}
Run Code Online (Sandbox Code Playgroud)

但是我不知道如何从RestTemplate获取它们,如何从ResponseEntity>获取类

ResponseEntity<List<Menu>> response = restTemplate
                  .exchange("http://127.0.0.1:8080/elcor/api/users/1/menus", HttpMethod.GET, entity,  ResponseEntity<List<Menu>>.getClass());
Run Code Online (Sandbox Code Playgroud)

rest spring-mvc resttemplate restful-architecture spring-boot

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

自定义功能接口SummaryStatistics

我有一个基本的SpringBoot应用程序.使用Spring Initializer,JPA,嵌入式Tomcat,Thymeleaf模板引擎和包作为可执行JAR文件我想创建一个基于POJO的自定义SummaryStatistics,它有2个字段,price和updateDate.此统计数据应该是最小/最大价格和最小/最大价格的日期.

public class MenuPriceSummaryStatistics implements Consumer<MenuPrice> {

    private long count;
    private double sum;
    private double sumCompensation; // Low order bits of sum
    private double simpleSum; // Used to compute right sum for non-finite inputs
    private double min = Double.POSITIVE_INFINITY;
    private double max = Double.NEGATIVE_INFINITY;

    private Date maxDate;
    private Date minDate;

    public MenuPriceSummaryStatistics() {
    }

    /**
     * Combines the state of another {@code DoubleSummaryStatistics} into this one.
     *
     * @param other
     *            another {@code DoubleSummaryStatistics}
     * @throws NullPointerException
     *             if …
Run Code Online (Sandbox Code Playgroud)

lambda functional-programming java-8 java-stream functional-interface

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

AWS - 创建一个 AmazonSNSClient

我想创建一个 AmazonSNSClient,我使用这段代码:

AmazonSNSClient snsClient = (AmazonSNSClient) AmazonSNSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(new PropertiesCredentials(is))).build();
Run Code Online (Sandbox Code Playgroud)

但我收到此错误:

线程“main”中的异常 java.lang.UnsupportedOperationException:客户端在使用构建器创建时是不可变的。

在 com.amazonaws.AmazonWebServiceClient.checkMutability(AmazonWebServiceClient.java:937)
在 com.amazonaws.AmazonWebServiceClient.setRegion(AmazonWebServiceClient.java:422)

java amazon-web-services amazon-sns

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