小编Mud*_*sar的帖子

如何在Spring中将对象添加到应用程序范围

我们可以在Spring中使用ModelModelAndView对象设置请求属性.

我们可以使用@SessionAttributes在会话范围内保留属性.

那么如何application在Spring 中将属性放在范围内,spring是否为此提供了任何注释?

spring scope spring-mvc

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

带有自定义标头的 Resttemplate GET 请求

我需要发送一个头的GET请求:Content-Type: application/camiant-msr-v2.0+xml。我期望来自服务器的 XML 响应。我用 Postman 测试了请求和响应,一切都很好。但是当我尝试在 Spring 中使用 时RestTemplate,我总是收到 400 个错误的请求。例外情况spring是:

Jul 09, 2016 12:53:38 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [/smp] threw exception [Request processing failed; nested exception is org.springframework.web.client.HttpClientErrorException: 400 Bad Request] with root cause
org.springframework.web.client.HttpClientErrorException: 400 Bad Request
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
    at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:641)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:597)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:475)
Run Code Online (Sandbox Code Playgroud)

我的代码:

MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>();
headers.add("Content-Type", "application/camiant-msr-v2.0+xml");

HttpEntity<?> entity = new HttpEntity<Object>(headers);
log.debug("request headers: …
Run Code Online (Sandbox Code Playgroud)

rest spring custom-headers resttemplate

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

得到“没有定义合格的 bean 类型。”

我遇到异常 -

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.muztaba.service.VerdictServiceImpl] is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:372)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:332)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1066)
at com.muztaba.service.App.task(App.java:35)
at com.muztaba.service.App.main(App.java:28)
Run Code Online (Sandbox Code Playgroud)

这是我得到异常的班级。

@Component
public class App {

QueueService<Submission> queue;

Compiler compiler;

VerdictService verdictService;

public static void main( String[] args ) {
    new App().task();
}

private void task() {
    AbstractApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
    queue =  context.getBean(QueueImpl.class);
    compiler = context.getBean(CompilerImpl.class);
    verdictService = context.getBean(VerdictServiceImpl.class); //here the exception thrown. 

    while (true) {
        if (!queue.isEmpty()) {
            Submission submission = queue.get();
            compiler.submit(submission);
        }
    }
} …
Run Code Online (Sandbox Code Playgroud)

spring ioc-container autowired

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

Spring SimpleJdbcInsert vs JdbcTemplate

我有一个要求,我必须在数据库中插入一行并获得密钥(身份).我想到了使用SimpleJdbcInsert.我将对象传递JdbcTemplate给我SimpleJdbcInsert和执行方法executeAndReturnKey().

同样可以做到用update()的方法,JdbcTemplate通过设置PreparedStatement,而不是参数地图.

我只是想知道JdbcTemplate在性能方面是否更好,我应该在SimpleJdbcInsert上使用它吗?如果是这样,那么它的卓越性能是什么原因呢?

注意:我不是插入一批记录而是仅插入一条记录.

谢谢

performance spring spring-jdbc jdbctemplate simplejdbcinsert

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

将jdbctemple结果转换为json的最有效方法?

一种方法是转换List< Map < String, Object>>List(object);Given Below

List<Map<String, Object>> ls = jdbcTemplate.queryForList(query);

List<Users> ls_o =  new ArrayList<>(ls_o);
        for (Map<String, Object> row : ls) {
        ls_o.add(row);

        }
 return new ResponseEntity<List<User>>(ls_o, HttpStatus.OK);
Run Code Online (Sandbox Code Playgroud)

是否有任何有效的方法直接将jdbcTemplate结果转换为json对象?

spring json spring-mvc spring-jdbc jdbctemplate

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

org.hibernate.LazyInitializationException:无法延迟初始化角色集合:没有会话或会话被关闭

我指定我的实体如下

 package com.drishti.training.dbentity;

import java.util.List;

import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Table;

import com.drishti.dacx.core.framework.ameyoentitytypes.AbstractDBEntity;

/**
 *
 */
@Entity
@Table(name = "template")
public class TemplateDBEntity extends AbstractDBEntity {

    String template_name, organisationId;

    @Column(name = "organisation_id", nullable = false)
    public String getOrganisationId() {
        return organisationId;
    }

    public void setOrganisationId(String organisationId) {
        this.organisationId = organisationId;
    }

    private String templateId;
    //    private List<Integer> listOfTrainingIds;

    private List<String> listOfTrainingIds;

    @Id
    @Column(name = "template_id", nullable = false)
    public String getTemplateId() { …
Run Code Online (Sandbox Code Playgroud)

java hibernate

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