我尝试过如下,但在两种情况下它都显示同一时间?我做错了什么.
LocalDateTime currentTime = LocalDateTime.now(ZoneId.of("UTC"));
Instant instant = currentTime.toInstant(ZoneOffset.UTC);
Date currentDate = Date.from(instant);
System.out.println("Current Date = " + currentDate);
currentTime.plusHours(12);
Instant instant2 = currentTime.toInstant(ZoneOffset.UTC);
Date expiryDate = Date.from(instant2);
System.out.println("After 12 Hours = " + expiryDate);
Run Code Online (Sandbox Code Playgroud)
"当前日期"时间与"12小时后"相同...
我想连接到Sonic Broker主题并侦听任何传入的XML消息.我做了类似下面的事情;
Application.java
@SpringBootApplication
@ComponentScan({"com.mainpack", "com.msgpack.jms"})
@EnableJms
public class Application extends SpringBootServletInitializer {
@Autowired
private JmsTopicListener jmsTopicListener;
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
try {
LogService.info(Application.class.getName(), "Starting Service...");
super.onStartup(servletContext);
jmsTopicListener.listenMessage();
LogService.info(Application.class.getName(), "Service Started");
} catch (Exception ex) {
LogService.error(this.getClass().getName(), ex);
}
}
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(Application.class, args);
LogService.info(Application.class.getName(), "Service Started...");
}
}
Run Code Online (Sandbox Code Playgroud)
JmsTopicListener.java
@Component
public class JmsTopicListener {
@Autowired
private ApplicationProperties properties; …Run Code Online (Sandbox Code Playgroud) 我想在收到请求时在数据库中进行检查.所以我做了如下的拦截器,
CustomInterceptor.java
@Component
public class CustomInterceptor extends HandlerInterceptorAdapter {
@Autowired
private DatabaseService databaseService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//Set Request Attribute(TODO)
LogService.info(this.getClass().getName(), "New Request URI is:" + request.getRequestURI());
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
String authToken = request.getHeader("AuthToken");
boolean isValidRequest = databaseService.checkIfTokenIsValid(authToken);
}
}
Run Code Online (Sandbox Code Playgroud)
Application.class:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
// protected Properties props = new Properties();
//
// public …Run Code Online (Sandbox Code Playgroud) 我想匹配的字符串可以是KH1或KH2或... KH99.
我做到了,
public class Test1 {
public static void main(String[] args) {
String name = "KH1";
if(name.matches("[[K][H][1-9][0-9]]") || name.matches("[[K][H][1-9]]")){
System.out.println("VALID NAME");
}else{
System.out.println("INVALID NAME");
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是行不通的.我得到INVALID NAME.
这是正确的方法是什么?
当我喜欢下面的时候,
GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
calendar.setTime(startTime); // startTime Date
DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);
Run Code Online (Sandbox Code Playgroud)
我得到像输出2015-04-15T11:04:30.000Z.
我希望它像2015-04-15T11:04:30.000.
有没有办法实现这个目标?
如下所示,
LocalDateTime currentUTCTime = LocalDateTime.now(ZoneId.of("UTC"));
String reqPattern = currentUTCTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss:SSS"));
System.out.println("Required pattern: " + reqPattern);
GregorianCalendar calendar = GregorianCalendar.from(currentUTCTime.atZone(ZoneId.systemDefault()));
XMLGregorianCalendar xcal = DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);
System.out.println("But Showing As :" + xcal);
Run Code Online (Sandbox Code Playgroud)
我希望输出为2015-06-18 11:59:15:135,但是当我设置xcal为XML标记时XMLGregorianCalender,它显示为2015-06-18T11:59:15.135+05:30.
我该如何删除该+05:30部分?
我的网络安全配置如下所示;
@EnableWebSecurity
@Configuration
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
}
@Override
protected void configure(AuthenticationManagerBuilder builder) throws Exception {
builder.inMemoryAuthentication().withUser("hellouser")
.password("hellopass").roles("USER");
}
}
Run Code Online (Sandbox Code Playgroud)
当我提供错误的用户名时,身份验证会按预期失败。但是,如果我在身份验证中成功一次,则此后所有其他密码错误但用户名正确的请求都将成功通过身份验证....
它是否被缓存在某处?
我可以禁用此功能吗?
是不是假设密码错误会导致身份验证失败?
注意:我正在学习 spring-security。我在这个应用程序中没有任何 html 页面,也没有来自 PostMan 的测试。
我想写下面的测试;
有一个叫听者state-info-1在src/main.
它对它获得的任何消息进行一些更改,并在activemq主题上发布新消息state-info-2.
我将构建一个虚拟消息并发布到activemq主题state-info-1.
最后验证,收到的关于主题的消息state-info-2就像我预期的那样.
我的听众就像;
@JmsListener(destination = "state-info-1", containerFactory = "connFactory")
public void receiveMessage(Message payload) {
// Do Stuff and Publish to state-info-2
}
Run Code Online (Sandbox Code Playgroud)
我可以为此写测试吗?或者我必须以其他方式做到这一点?
另外,我看了这个:https://github.com/spring-projects/spring-boot/blob/master/spring-boot-samples/spring-boot-sample-activemq/src/test/java/sample/activemq /SampleActiveMqTests.java
但这不是我所期待的.
任何帮助或推动正确的方向就足够了.
感谢您的时间.
我按照这个例子在示例项目中创建了一个计划任务:https: //spring.io/guides/gs/scheduling-tasks
它说, @EnableScheduling ensures that a background task executor is created. Without it, nothing gets scheduled.
但是,我错误地没有使用它.怎么还能运作?
的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>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins> …Run Code Online (Sandbox Code Playgroud) spring-boot ×5
java ×4
java-8 ×4
java-time ×2
spring ×2
jms ×1
regex ×1
sonicmq ×1
spring-jms ×1
spring-test ×1
springfox ×1
swagger-2.0 ×1
swagger-ui ×1
xsd ×1