在gradle build我的Web应用程序的根目录中运行后,声明的spring安全性依赖项build.gradle不会被下载.
这是我的 build.gradle
/*
* This build file was auto generated by running the Gradle 'init' task
* by 'hombod' at '7/19/16 4:19 PM' with Gradle 2.14.1
*
* This generated file contains a commented-out sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at https://docs.gradle.org/2.14.1/userguide/tutorial_java_projects.html
*/
// Apply the java plugin to add support for Java
apply …Run Code Online (Sandbox Code Playgroud) 我想基于现有的Eclipse安装创建一个Oomph产品安装文件.有没有办法生成安装文件作为当前安装的一种快照?
我有一个包含两列(纬度,经度)的csv文件,其中包含超过500万行的地理位置数据.我需要识别与列表中任何其他点不在5英里范围内的点,并将所有内容输出回另一个具有额外列的CSV(CloseToAnotherPoint),True如果有另一个点在5英里内,并且False如果有"T.
这是我当前使用的解决方案geopy(不进行任何Web调用,只使用函数来计算距离):
from geopy.point import Point
from geopy.distance import vincenty
import csv
class CustomGeoPoint(object):
def __init__(self, latitude, longitude):
self.location = Point(latitude, longitude)
self.close_to_another_point = False
try:
output = open('output.csv','w')
writer = csv.writer(output, delimiter = ',', quoting=csv.QUOTE_ALL)
writer.writerow(['Latitude', 'Longitude', 'CloseToAnotherPoint'])
# 5 miles
close_limit = 5
geo_points = []
with open('geo_input.csv', newline='') as geo_csv:
reader = csv.reader(geo_csv)
next(reader, None) # skip the headers
for row in reader:
geo_points.append(CustomGeoPoint(row[0], row[1]))
# for every point, …Run Code Online (Sandbox Code Playgroud) 我想创建一个自定义Eclipse,它具有Mybatipse以及默认安装的其他一些插件.我正在使用Eclipse中的Oomph产品设置来创建我的产品.我的猜测是在P2 director节点中添加一个要求,但我不知道如何正确设置它.我已经看过将插件的名称放在需求的名称部分中的示例,org.eclipse.emf.compare.source.feature.group但我不知道从哪里获取我想要的插件的信息.我甚至走向了正确的方向吗?
在调试模式下启动应用程序时,它询问我是否要打开调试透视图.我检查了我的决定,但必须不小心点击'是'而不是'否'.我该怎么撤消这个?
我正在尝试获取下一个即将到来的星期五的日期,并将其格式设置为yyyyMMDD。如果可能,我想不使用JodaTime来执行此操作。这是我的代码:
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.time.DayOfWeek;
import java.time.format.DateTimeFormatter;
// snippet from main method
LocalDate friday = LocalDate.now().with(TemporalAdjusters.next(DayOfWeek.FRIDAY));
DateTimeFormatter formatter = DateTimeFormatter.ofPattern('yyyyMMDD');
System.out.println(friday.format(formatter));
Run Code Online (Sandbox Code Playgroud)
但是当我运行此命令时,出现以下错误(今天运行20170809)
java.time.DateTimeException: Field DayOfYear cannot be printed as the value 223 exceeds the maximum print width of 2
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
编辑:我正在使用Java 8
在我对UserDetailsService的自定义实现使用Bcrypt之前,我首先想看看我是否可以在内存数据库中使用它.
package com.patrick.Security;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
private UserDetailsService userDetailsService;
@Autowired
public WebSecurityConfig(UserDetailsService userDetailsService) {
this.userDetailsService = userDetailsService;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers(HttpMethod.POST, "/login").permitAll()
.antMatchers(HttpMethod.POST, "/users").hasAuthority("ADMIN")
.antMatchers(HttpMethod.POST, "/shifts").hasAnyAuthority("ADMIN", "SUPERVISOR")
.anyRequest().authenticated()
.and()
.addFilter(new AuthenticationFilter(authenticationManager()))
.addFilter(new AuthorizationFilter(authenticationManager()));
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().passwordEncoder(passwordEncoder()) …Run Code Online (Sandbox Code Playgroud) 我正在做一个计划项目,该项目定期执行多个作业。我正在使用cron调度,如下例所示。作业已成功执行,没有问题。但是,出于需求,我想计算并保留DB中计划作业的下一次运行时间。对于以下配置,是否有解决方案来获取作业的上一次和下一次启动时间?
配置示例:
import java.util.Date;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;
@Component
@EnableScheduling
public class DemoServiceBasicUsageCron
{
@Scheduled(cron="1,3,30,32 * * * * ?")
public void demoServiceMethod()
{
System.out.println("Curent date time is - "+ new Date());
}
}
Run Code Online (Sandbox Code Playgroud) 在spring mvc应用程序中配置spring安全性后,运行它时出现以下错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.util.AntPathMatcher.setCaseSensitive(Z)V
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.__refresh(AbstractApplicationContext.java:480) …Run Code Online (Sandbox Code Playgroud) 我调试,旨在妥善处理的情况下,一个应用程序foo是null.然而,当从生产中检查日志时,NullPointerException尝试访问foo应该正常处理的方法后抛出了一个.
它看起来像这样
if (foo == null) {
throw new GracefulException();
}
Bar bar = foo.getBar();
Run Code Online (Sandbox Code Playgroud)
因此,使用该代码NullPointerException时,调用时会在生产中发生foo.getBar().
我的问题很简单:有没有人听说过这样的时髦行为,甚至可能发生?如果是这样,可能导致什么呢?
该文档的org.springframework.restdocs.RestDocumentation,它已被弃用状态.
我试图在这样的JUnit测试中使用该类:
@Rule
public RestDocumentation restDocumentation = new RestDocumentation("target/generated-snippets");
Run Code Online (Sandbox Code Playgroud)
我应该使用什么课?
I am trying to hook into the creation of the context using a custom application listener like this
@Component
public class ContextStartedListener implements ApplicationListener<ContextStartedEvent> {
@Override
public void onApplicationEvent(ContextStartedEvent event) {
System.out.println("Context started"); // this never happens
}
}
Run Code Online (Sandbox Code Playgroud)
But the onApplicationEvent method never fires. If I use a different event such as ContextRefreshedEvent then it works just fine, but I need to hook into before it is created. Any advice? Thanks!