我正在尝试使用java 9和gradle的spring boot.我无法运行我的简单代码,我得到以下提到的错误: -
Information:java: Errors occurred while compiling module 'Java9Gradle_main'
Information:javac 9-ea was used to compile java sources
Information:6/9/2017 10:40 PM - Compilation completed with 65 errors and 0 warnings in 15s 200ms
Error:java: module reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.starter.web reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.starter.web reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.autoconfigure reads …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用酶来测试反应组分,但即使用最基本的例子也无法开始.
import React from 'react'
import { shallow,render,mount,configure } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16';
import {LoginPage} from '../../../app/components/login/LoginPage'
configure({ adapter: new Adapter() });
test('should say hello',() => {
const loginPage = shallow(<LoginPage />)
expect(loginPage.contains('Hello').toBe(true))
})
Run Code Online (Sandbox Code Playgroud)
运行时,我收到以下错误: -
Test suite failed to run
D:/code/github/metallica2/metallica/client/src/app/__tests__/components/login/LoginPage.test.js: Unexpected token (9
:30)
7 |
8 | test('should say hello',() => {
> 9 | const loginPage = shallow(<LoginPage />)
| ^
10 | expect(loginPage.contains('Hello').toBe(true))
11 | })
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?
谢谢,
阿马尔
我有3个yml文件
application-default.yml - >默认属性,应该在所有配置文件中都可用application-dev.yml - >仅适用于dev配置文件的属性application-prod.yml - >仅适用于prod配置文件的属性当我通过传递启动我的启动应用程序时-Dspring.profiles.active=dev,我能够访问application-dev.yml特定的属性.但我无法获得application-default.yml文件中定义的属性.以下是我的application-dev.yml档案:
Spring:
profiles:
include: default
spring.profiles: dev
prop:
key:value
Run Code Online (Sandbox Code Playgroud) 我刚刚开始使用 Spring 批处理并陷入了这个问题。我的工作永无止境,无限循环。以下是代码:-
@SpringBootApplication
@EnableBatchProcessing
public class Main implements CommandLineRunner{
@Autowired
private JobBuilderFactory jobBuilderFactory;
@Autowired
private StepBuilderFactory stepBuilderFactory;
@Autowired
private JobLauncher jobLauncher;
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
@Override
public void run(String... args) throws Exception {
jobLauncher.run(flattenPersonJob(),new JobParameters());
System.out.println("Done");
}
@Bean
public ItemReader itemReader() {
return new PersonReader();
}
@Bean
public ItemProcessor itemProcessor() {
return new PersonProcessor();
}
@Bean
public ItemWriter itemWriter() {
return new PersonWriter();
}
@Bean
public Step flattenPersonStep() {
return stepBuilderFactory.get("flattenPersonStep").
chunk(1).
reader(itemReader()).
processor(itemProcessor()). …Run Code Online (Sandbox Code Playgroud) 我试图了解流中的 reduce 方法是如何工作的。
Stream.of(1,2,3,4,5,6,7).reduce(new ArrayList<>(),
(List<Integer> l, Integer a) -> {l.add(a);return l;},
(List<Integer> l1, List<Integer> l2) -> {
System.out.println("l1 is" + l1 + "l2 is " + l2);
l1.addAll(l2);
return l1;
}).forEach(System.out::println);
Run Code Online (Sandbox Code Playgroud)
该行System.out.println("l1 is" + l1 + "l2 is " + l2)永远不会被打印。我可以理解发生了什么,(List<Integer> l, Integer a) -> {l.add(a);return l;}
有人可以解释为什么没有打印出来吗?java文档说function for combining two values, which must be compatible with the accumulator function
谢谢,阿马尔
我试图从我的控制器中的相同方法生成XML和JSON响应.我用Google搜索并发现JSON是spring的默认值,因为jackson在classpath上.但对于XML,我必须添加JAXB依赖项,然后使用JAXB注释注释我的模型.另外,我不得不更改@RequestMapping注释的produce属性.
现在,我的默认行为已更改,它返回XML响应.我想在使用值application/json将content-Type标头添加到我的请求后,我的响应将是JSON,但遗憾的是情况并非如此.以下是我的代码: -
package com.example.controller;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.domain.Person;
@RestController("person")
public class PersonController {
@RequestMapping(name ="getperson", produces = {MediaType.APPLICATION_XML_VALUE,MediaType.APPLICATION_JSON_VALUE})
public Person getPerson() {
Person p = new Person();
p.setAge(28);
p.setEmail("email@gmail.com");
p.setName("Amar");
return p;
}
}
Run Code Online (Sandbox Code Playgroud)
型号类: -
package com.example.domain;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Person {
//@XmlElement
private String name;
//@XmlElement
private int age;
private String email;
public String getName() {
return name;
}
@XmlElement
public void setName(String name) {
this.name = name;
} …Run Code Online (Sandbox Code Playgroud) 我有一个服务,它从数据库中查询优惠券列表。此服务Optional向客户端返回。
return listOfCoupons.isEmpty() ? Optional.empty() : Optional.of(listOfCoupons.get(listOfCoupons.size() - 1));
Run Code Online (Sandbox Code Playgroud)
此代码的客户端Optional以以下方式使用命名的“优惠券”:
if (coupons.isPresent) {
save (coupons.get());
}
Run Code Online (Sandbox Code Playgroud)
这是正确的用法Optional吗?
我正在尝试使用Java配置将spring Boot与Hibernate 5集成.我使用Hibernate已经有一段时间了.我得到了下面提到的例外.有人可以建议如何解决这个问题吗?
以下是我的java配置文件,后跟异常堆栈跟踪.
package com.example;
import com.example.dao.CustomerDao;
import com.example.model.Customer;
import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;
import java.util.Properties;
@SpringBootApplication
@EnableTransactionManagement
public class SpringHibernateDemoApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(SpringHibernateDemoApplication.class, args);
}
@Bean
public DataSource dataSource() throws ClassNotFoundException {
//SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
// dataSource.setDriverClass((Class<? extends Driver>)Class.forName("com.mysql.jdbc.Driver"));
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/customerDB");
dataSource.setUsername("root");
dataSource.setPassword("welcome");
return dataSource;
}
@Bean
public LocalSessionFactoryBean sessionFactory() throws …Run Code Online (Sandbox Code Playgroud) java ×5
spring-boot ×5
spring ×4
java-8 ×2
enzyme ×1
gradle ×1
hibernate ×1
java-9 ×1
java-module ×1
java-stream ×1
jestjs ×1
json ×1
optional ×1
reactjs ×1
rest ×1
spring-batch ×1
spring-mvc ×1
yaml ×1