我已经按照本教程.现在,如果我通过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个问题.
注意:默认情况下,它使用测试vile运行spring boot,我可以通过简单的控制器(而不是@RepositoryRestResource)使其工作,但我希望能够卷曲http://localhost:8080并获得选项响应.
我有简单的Spring Data JPA存储库.
public interface UserRepository extends JpaRepository<UserEntity, Serializable>{ … }
Run Code Online (Sandbox Code Playgroud)
有没有办法监视Spring生成的方法的执行时间(例如findOne(…))?
我有一个具有复合键的实体,我试图通过使用 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) 我想创建一个具有自定义行为的Spring Data JPA存储库,并使用Specification实现该自定义行为.我已经通过Spring Data JPA文档在单个存储库中实现自定义行为来设置它,除了没有在自定义存储库中使用Spring Data Specification的示例.如果可能的话,如何做到这一点?
我没有看到一种方法将某些内容注入到需要规范的自定义实现中.我认为我会很棘手,并将存储库的CRUD存储库部分注入自定义部分,但这会导致循环实例化依赖.
我没有使用QueryDSL.谢谢.
我目前使用的是 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
我坚持这个错误:
我想使用一个使用谓词进行搜索的方法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) 我使用 Spring Boot、Spring Data JPA 和 Hibernate。
我需要过滤EntityManager由自定义注释管理的实体。LocalContainerEntityManagerFactoryBean允许设置被扫描的包列表,但过滤器似乎是硬编码在DefaultPersistenceUnitManager.
否则LocalSessionFactoryBuilder(特定于 Hibernate 的)具有此功能(方法setEntityTypeFilters),但不能与需要EntityManagerFactory.
如何将实体过滤应用于LocalContainerEntityManagerFactoryBean?
当前,我们已经配置并运行了Spring 3.2.9.RELEASE(已经运行了几年),需要迁移到4.1.4.RELEASE。我们有一个抽象的DAO类,它扩展org.springframework.orm.jpa.support.JpaDaoSupport了以下内容:
org.springframework.orm.jpa.JpaCallbackorg.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及其配置设置还很陌生。
想象一下,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) 我有一个关于 Spring Data 存储库如何处理数据源连接的问题。假设 Spring Data 存储库在方法执行时打开和关闭连接和连接,如何通过@Transactional在我的服务层中声明跨越多个存储库调用来启动事务?
谁处理数据库连接?该@Transactional注解或JPA资料库?
jpa ×7
spring-data ×7
spring ×6
java ×5
hal ×1
hibernate ×1
hypermedia ×1
json ×1
mongodb ×1
querydsl ×1
rest ×1
spring-4 ×1
spring-boot ×1
transactions ×1