小编Ree*_*uuk的帖子

GSON解析没有很多类

我有以下JSON,我只对获取元素感兴趣"status","lat"并且"lng".

使用Gson,是否可以解析此JSON以获取这些值而无需创建表示JSON内容的整个类结构?

JSON:

{
  "result": {
    "geometry": {
      "location": {
        "lat": 45.80355369999999,
        "lng": 15.9363229
      }
    }
  },
  "status": "OK"
}
Run Code Online (Sandbox Code Playgroud)

java parsing json gson

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

Thymeleaf + Boot + AngularJS指令解析器错误

这应该是一个简单的,但我找不到任何解决方案.

我在Jetty上使用Spring Boot 1.0.2和Thymeleaf来支持我的AngularJS应用程序.但是当使用属性指令时,解析器会抛出异常.

的pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<dependency>
    <groupId>net.sourceforge.nekohtml</groupId>
    <artifactId>nekohtml</artifactId>
    <version>1.9.20</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

Thymeleaf配置

@Configuration
public class ThymeleafConfig {

    @Bean
    public ServletContextTemplateResolver templateResolver() {
        ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
        resolver.setPrefix("/templates/");
        resolver.setSuffix(".html");
        resolver.setTemplateMode("LEGACYHTML5");
        resolver.setCacheable(false);
        return resolver;
    }

    @Bean
    public ResourceBundleMessageSource messageSource() {
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        messageSource.setBasename("messages");
        messageSource.setDefaultEncoding("UTF-8");

        return messageSource;
    }
}
Run Code Online (Sandbox Code Playgroud)

Thymeleaf工作正常,但是像这个Bootstrap UI示例的属性指令有问题:

<div class="btn-group" dropdown is-open="true">
    <button type="button" class="btn btn-primary dropdown-toggle">
        Button dropdown<span class="caret"></span>
    </button>
    <ul class="dropdown-menu" role="menu">
        <li><a href="#">Action</a></li>
        <li><a href="#">Another action</a></li>
        <li><a href="#">Something else here</a></li> …
Run Code Online (Sandbox Code Playgroud)

spring angularjs thymeleaf spring-boot

9
推荐指数
3
解决办法
8895
查看次数

Jersey ExceptionMapper不映射异常

我的Spring Boot + Jersey REST服务无法按预期工作.

UserController抛出了EmailExistsException,但我只收到错误500.一直都是.我的例外情况没有记录.

我怀疑异常处理存在一些配置问题,但不知道在哪里设置它.有什么建议?

@POST
@Path("register")
@Produces(MediaType.APPLICATION_JSON)
public Response register(NewUserPayload newUserPayload) throws EmailExistsException, MessagingException
Run Code Online (Sandbox Code Playgroud)

EmailExistsExceptionMapper

@Provider
public class EmailExistsExceptionMapper extends AbstractExceptionMapper       implements
    ExceptionMapper<EmailExistsException>
{
@Override
public Response toResponse(EmailExistsException e)
{
    ResponseEntity re = new ResponseEntity(org.springframework.http.HttpStatus.BAD_REQUEST);

    return this.errorResponse(HttpStatus.BAD_REQUEST_400, re, e);
}
}
Run Code Online (Sandbox Code Playgroud)

AbstractExceptionMapper

@Slf4j
public abstract class AbstractExceptionMapper
{
protected Response errorResponse(int status, ResponseEntity responseEntity, Throwable t)
{
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    t.printStackTrace(pw);
    log.error(sw.toString()); // logging stack trace.

    return customizeResponse(status, responseEntity);
} …
Run Code Online (Sandbox Code Playgroud)

rest spring web-services jersey spring-boot

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

akka-http:找不到参数解组的隐式值

我的喷雾 json 支持看起来像这样

object MarshallingSupport extends SprayJsonSupport {
  implicit def json4sFormats: Formats = DefaultFormats
}
Run Code Online (Sandbox Code Playgroud)

在我的路线中,我想将请求映射到 dto

object Main extends App with AppConfig with BaseService with MainActorSystem {

  val processor = system.actorOf(Props(), "processorActor")
  val view = system.actorOf(Props(), "processorActor")

  override protected implicit val executor: ExecutionContext = system.dispatcher
  override protected val log: LoggingAdapter = Logging(system, getClass)
  override protected implicit val materializer: ActorMaterializer = ActorMaterializer()

  Http().bindAndHandle(routes(processor, view), httpInterface, httpPort)
}

trait BaseServiceRoute {
  protected implicit def executor: ExecutionContext
  protected implicit def materializer: ActorMaterializer …
Run Code Online (Sandbox Code Playgroud)

scala akka spray spray-json akka-http

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

Thymeleaf不会抓取页面

这是我用Thymeleaf设置的Spring Boot.

的pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

ThymeleafConfig

@Configuration
public class ThymeleafConfig {

    @Bean
    public ServletContextTemplateResolver templateResolver() {
        ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
        resolver.setPrefix("/templates/");
        resolver.setSuffix(".html");
        resolver.setTemplateMode("LEGACYHTML5");
        resolver.setOrder(1);
        return resolver;
    }
}
Run Code Online (Sandbox Code Playgroud)

调节器

@RestController
public class WebController {

    @RequestMapping("")
    public String index(){
        return "index";
    }
}
Run Code Online (Sandbox Code Playgroud)

Index.html位于src/main/resources/templates中.

但是当调用localhost:8080时,只会呈现"index"字符串.未获取Index.html.可能是什么问题呢?

spring spring-mvc thymeleaf spring-boot

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

Spring Boot + Jetty和热部署

我已经阅读了Spring Boot中的热插拔,但没有找到对我的情况有帮助的东西.

我在使用thymeleaf的嵌入式码头服务器上有一个spring-boot应用程序.我的应用程序将提供html,css,js(AngularJS)和REST服务.

文件夹结构是这样的:

/java
   ----
/resources
   /static
       /js
       /css
   /templates (html)
Run Code Online (Sandbox Code Playgroud)

的pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

但是当我更改它们时,css/html/js并没有热部署.我每次都要重启服务器.+ bonus =当页面加载时它锁定资源(js)甚至Ant脚本也无法替换它们.

我可以在任何地方设置scanIntervalSeconds吗?

- 编辑 -

Main.java

@Configuration
@ComponentScan
@EnableJpaRepositories
@EnableAutoConfiguration
@Import({RepositoryRestMvcConfiguration.class, PersistenceConfig.class, ThymeleafConfig.class})
public class Main {

   public static void main(String[] args) throws Exception {
       SpringApplication.run(Main.class, args);
   }
}
Run Code Online (Sandbox Code Playgroud)

我通过右键单击类和IDEA中的Debug来运行它.

deployment spring jetty maven spring-boot

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