小编Oli*_*ohm的帖子

部署到独立Tomcat时,Spring Boot应用程序无法正常工作

我已经按照本教程.现在,如果我通过Spring Boot使用它,它可以工作,但如果我尝试在Apache Tomcat 7上部署它(删除应用程序类),我会收到404响应.我也尝试过自己的配置 - 像这样:

@Configuration
public class MongoConfiguration {

    public @Bean MongoDbFactory mongoDbFactory() throws Exception {
        return new SimpleMongoDbFactory(new Mongo("127.0.0.1", 27017), "movies");
    }

    public @Bean MongoTemplate mongoTemplate() throws Exception {
        return new MongoTemplate(mongoDbFactory());
    }
}
Run Code Online (Sandbox Code Playgroud)

它仍然无法正常工作.所以2个问题.

  1. 如何在tomcat上运行它(如何在tomcat上进行简单的休息和运行)
  2. 如何通过注释配置mongo(只是为了获取我的数据库)

注意:默认情况下,它使用测试vile运行spring boot,我可以通过简单的控制器(而不是@RepositoryRestResource)使其工作,但我希望能够卷曲http://localhost:8080并获得选项响应.

spring-data-rest spring-data-mongodb spring-boot

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

如何记录Spring Data JPA存储库方法的执行时间?

我有简单的Spring Data JPA存储库.

public interface UserRepository extends JpaRepository<UserEntity, Serializable>{ … }
Run Code Online (Sandbox Code Playgroud)

有没有办法监视Spring生成的方法的执行时间(例如findOne(…))?

java spring jpa spring-data spring-data-jpa

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

spring data jpa复合键重复键记录插入导致更新

我有一个具有复合键的实体,我试图通过使用 spring data jpa 存储库到 mysql 数据库来持久化它,如下所示:

@Embeddable
public class MobileVerificationKey implements Serializable{
private static final long serialVersionUID = 1L;

@Column(name="CUSTOMERID")
private Long customerId;

@Column(name="CUSTOMERTYPE")
private Integer customerType;

@Column(name="MOBILE")
private Long mobile;
@Embeddable
public class MobileVerificationKey implements Serializable{

    private static final long serialVersionUID = 1L;

    @Column(name="CUSTOMERID")
    private Long customerId;

    @Column(name="CUSTOMERTYPE")
    private Integer customerType;

    @Column(name="MOBILE")
    private Long mobile;
//getter and setters
}
Run Code Online (Sandbox Code Playgroud)

和实体作为

@Entity
@Table(name="mobileverificationdetails")
public class MobileVerificationDetails {

    @EmbeddedId
    private MobileVerificationKey key;

    @Column(name="MOBILETYPE")
    private String mobileType;

    @Column(name="MOBILEPIN")
    private Integer mobilePin; …
Run Code Online (Sandbox Code Playgroud)

java spring jpa spring-data spring-data-jpa

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

Spring Data JPA:使用规范实现自定义存储库行为

我想创建一个具有自定义行为的Spring Data JPA存储库,并使用Specification实现该自定义行为.我已经通过Spring Data JPA文档在单个存储库中实现自定义行为来设置它,除了没有在自定义存储库中使用Spring Data Specification的示例.如果可能的话,如何做到这一点?

我没有看到一种方法将某些内容注入到需要规范的自定义实现中.我认为我会很棘手,并将存储库的CRUD存储库部分注入自定义部分,但这会导致循环实例化依赖.

我没有使用QueryDSL.谢谢.

java spring jpa spring-data spring-data-jpa

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

哪个版本的 Spring Data MongoDB 与 Spring 3.2.2.RELEASE 兼容?

我目前使用的是 mongo-java-driver 3.0.1。我正在尝试将 Spring Data Mongodb 与 Spring 3.2.2.RELEASE 一起使用。有什么方法可以找出应该使用哪个版本的 Spring Data MongoDB,以便与 Spring 3.2.2.RELEASE 兼容?某种兼容性矩阵。

compatibility spring mongodb spring-data spring-data-mongodb

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

spring数据JPA方法findAll()与Predicate - QueryDslPredicateExecutor

我坚持这个错误:

我想使用一个使用谓词进行搜索的方法QueryDslPredicateExecutor.当该方法在我的服务实现上运行时,我收到此错误:

16:59:44,165 DEBUG [org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver] (http-localhost-127.0.0.1-9090-4) Resolving exception from handler [public br.com.cleartech.itx.web.dto.PageDto br.com.cleartech.itx.web.controller.CngController.list(br.com.cleartech.itx.core.domain.Cng,org.springframework.data.domain.Pageable)]: org.springframework.data.mapping.PropertyReferenceException: No property cng found for type Cng!
16:59:44,167 DEBUG [org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver] (http-localhost-127.0.0.1-9090-4) Invoking @ExceptionHandler method: public org.springframework.web.servlet.ModelAndView br.com.cleartech.itx.web.exception.WebExceptionHandler.runtime(java.lang.Exception)
16:59:44,169 ERROR [br.com.cleartech.itx.web.exception.WebExceptionHandler] (http-localhost-127.0.0.1-9090-4) No property cng found for type Cng!
16:59:44,170 DEBUG [org.springframework.web.servlet.DispatcherServlet] (http-localhost-127.0.0.1-9090-4) Handler execution resulted in exception - forwarding to resolved error view: ModelAndView: reference to view with name 'error'; model is {exception=org.springframework.data.mapping.PropertyReferenceException: No property cng found for type Cng!}: org.springframework.data.mapping.PropertyReferenceException: No property cng …
Run Code Online (Sandbox Code Playgroud)

java hibernate jpa querydsl spring-data

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

如何过滤 LocalContainerEntityManagerFactoryBean 扫描的实体?

我使用 Spring Boot、Spring Data JPA 和 Hibernate。

我需要过滤EntityManager由自定义注释管理的实体。LocalContainerEntityManagerFactoryBean允许设置被扫描的包列表,但过滤器似乎是硬编码在DefaultPersistenceUnitManager.

否则LocalSessionFactoryBuilder(特定于 Hibernate 的)具有此功能(方法setEntityTypeFilters),但不能与需要EntityManagerFactory.

如何将实体过滤应用于LocalContainerEntityManagerFactoryBean

java spring jpa spring-data spring-data-jpa

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

如何将JpaTemplate的使用从Spring 3.2迁移到4.1.4?

当前,我们已经配置并运行了Spring 3.2.9.RELEASE(已经运行了几年),需要迁移到4.1.4.RELEASE。我们有一个抽象的DAO类,它扩展org.springframework.orm.jpa.support.JpaDaoSupport了以下内容:

  • org.springframework.orm.jpa.JpaCallback
  • org.springframework.orm.jpa.JpaTemplate

我已经看到JpaDaoSupport在Spring 4中已将其删除。我已删除了对Jpa *类的引用,并替换为

@PersistenceContext 
protected EntityManager theEntityManager;
Run Code Online (Sandbox Code Playgroud)

并在中找到我们DAO中的方法引用(如findByNamedParams()JpaDaoSupport,然后将其复制到我们的DAO中。

完成上述更改后,我们便可以编译我们的代码,但是当涉及到运行我们的JUnit测试时,我们applicationContext-test.xml

<bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<bean id="abstractDAO" abstract="true" class="my.company.package.AbstractDAO">
    <property name="jpaTemplate" ref="jpaTemplate" />
</bean>

<bean id="genericDAO" parent="abstractDAO" class="my.company.package.GenericDAO" />
<bean id="securityDAO" parent="abstractDAO" class="my.company.package.SecurityDAOImpl" />
Run Code Online (Sandbox Code Playgroud)

基本上错误是没有的类引用org.springframework.orm.jpa.JpaTemplate。我们如何JpaTemplate在Spring 4.1.4中替换此配置?

请注意,我选择的是这段代码,而不是最初配置系统的代码。另外,我对Spring及其配置设置还很陌生。

spring jpa spring-4

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

如何使用JSON HAL处理嵌套资源?

想象一下,REST端点(/employees)以JSON HAL格式提供员工页面.一名员工住在一个居住在非洲大陆的国家.

对于国家和大陆而言,也有单独的端点.

返回的页面包含_embedded具有员工数据的典型字段.员工资源还包含嵌套country资源.这个嵌套country资源也包含_links.

在这种情况下,输出将是:

GET /employees

{
  "_embedded": {
    "employees": [{
        "employee_id": 1
        "name": "Mr. X",
        "place_name": "London",
        "country": {
          "alpha2_code": "AU",
          "name": "Australia",
          "continent": {
            "code": "OC",
            "name": "Australia",
            "_links": {
              "self": {
                "href": "http://localhost:8077/continents/au"
              }
            }
          },
          "_links": {
            "self": {
              "href": "http://localhost:8077/countries/au"
            }
          }
        },
        "_links": {
          "self": {
            "href": "http://localhost:8077/employees/1"
          }
        }
      },
      {
      ..
      }
    ]
  },
  "_links": {
    "first": {
      "href": "http://localhost:8077/employees?page=1&size=10"
    }, …
Run Code Online (Sandbox Code Playgroud)

rest json domain-driven-design hal hypermedia

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

如何为 Spring Data JPA 存储库管理数据库连接?

我有一个关于 Spring Data 存储库如何处理数据源连接的问题。假设 Spring Data 存储库在方法执行时打开和关闭连接和连接,如何通过@Transactional在我的服务层中声明跨越多个存储库调用来启动事务?

谁处理数据库连接?该@Transactional注解或JPA资料库?

jpa transactions spring-data spring-data-jpa

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