使用Spring boot 1.3.1
我不明白为什么@RestController默认是Transactionnal.我在文档中没有发现任何这样的说法.
推动以下控制器中方法findOne()的事实是Transactionnal:
@RestController
@RequestMapping("/books")
public class BookController {
@RequestMapping("/{id}")
public Book findOne(@PathVariable Long id) {
Book book = this.bookDao.findOneBookById(id);
// following line
// => triggers a select author0_.id as id1_0_0_ etc... // where author0_.id=?
System.out.println(book.getAuthor().getFirstname());
return book;
}
}
Run Code Online (Sandbox Code Playgroud)
System.out.println的行(book.getAuthor().getFirstname()); 应该提出一个LazyInitiaizationFailure但这里它成功并触发一个作者的选择.所以方法findOne似乎是事务性的.使用eclipse调试器,我可以确定它确实是这一行触发了补充选择.但为什么那个方法是事务性的呢?
@Configuration
@ComponentScan(basePackageClasses = _Controller.class)
@Import(BusinessConfig.class)
public class WebConfig extends WebMvcConfigurerAdapter {
// ... here the conf to setup Jackson Hibernate4Module
}
@Configuration
@EnableAutoConfiguration
@EnableTransactionManagement
@EntityScan(basePackageClasses = _Model.class)
@ComponentScan(basePackageClasses = { _Dao.class })
public class BusinessConfig { …Run Code Online (Sandbox Code Playgroud) 在我使用的Spring Boot 1.3.0.M5下
spring.data.rest.max-page-size=10
Run Code Online (Sandbox Code Playgroud)
在application.properties 中。
但是我仍然可以在 URL 中将大小设置为 40 并获得正确的响应。例如:http://localhost:8080/cine20-spring/api/films?page=0&size=40&sort=title,asc
会给我40部电影
那么这个参数有什么用呢?
使用 Spring-Boot 1.4.2 更新测试
还有一个问题:默认情况下没有依赖 spring-boot-starter-data-rest ,默认情况下max-page-size 设置为2000并且更改 max-page-size 值将不起作用:
spring.data.rest.max-page-size=0x7fffffff
Run Code Online (Sandbox Code Playgroud)
添加spring-boot-starter-data-rest => max-page-size 现在默认设置为1000,然后更改参数 max-page-size 将起作用:
spring.data.rest.max-page-size=0x7fffffff
Run Code Online (Sandbox Code Playgroud)
我仍然相信,这是奇怪的行为。
在:https : //github.com/spring-projects/spring-data-rest/blob/master/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/config/存储库RestConfiguration.java
你可以找到private int maxPageSize = 1000;这解释了为什么它变成了 1000。我还没有找到,为什么它从一开始就设置为 2000。
我想spring.data.rest.max-page-size自由设置参数而不需要添加依赖项:spring-boot-starter-data-rest,但不幸的是我到目前为止还没有找到方法。
代理设置似乎在 Spring-Boot 1.5+ 和 2.+ 之间发生了变化。
在带有@EnableAspectJAutoProxy(proxyTargetClass = false) 或只是@EnableAspectJAutoProxy 或什至没有注释@EnableAspectJAutoProxy 的Spring 1.5.20 中,我会得到一个JdkDynamicAopProxy。使用 @EnableAspectJAutoProxy(proxyTargetClass = true) 我会得到 CGLIB 增强类。好的一切都好。
使用与 Spring 2.1.4 相同的代码,无论配置如何,我都会始终获得 CGLIB 增强的 ServiceImpl。
我没有设法在 Spring 2+ 中使用 JdkDynamicAopProxy 代理。
还有办法做到吗?
这是我的代码:
@SpringBootApplication
@EnableAspectJAutoProxy(proxyTargetClass = false)
public class DemoApplication {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(DemoApplication.class, args);
MyService service = context.getBean(MyService.class);
service.execute();
}
}
@Aspect
@Component
public class ChronoAspect {
@Around("execution(* com.example.demo.service..*.*(..))")
public Object chronoAround(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis(); …Run Code Online (Sandbox Code Playgroud) 我正在使用FilfetDto构建动态查询如果用户填充了UI中的某些字段,则包含一些值但不是全部.所以我必须测试每个属性以构建仅在填充(非空)字段上的查询过滤:
JPAQuery dslQuery = new JPAQuery(em);
dslQuery.from(book);
dslQuery.join(book.author, author);
String title = StringUtils.upperCase(StringUtils.trim(_filter.getTitle()));
if (StringUtils.isNotBlank(title)) {
dslQuery.where(book.title.upper().like(title));
}
String isbn = StringUtils.trim(_filter.getIsbn());
if (StringUtils.isNotBlank(isbn)) {
dslQuery.where(book.isbn.like(isbn));
}
if (_filter.getAuthorId() != null) {
dslQuery.where(author.id.eq(_filter.getAuthorId()));
}
Run Code Online (Sandbox Code Playgroud)
有没有办法用另一种更可读的语法来抽象"if"?
我想要像:
JPAQuery dslQuery = new JPAQuery(em);
dslQuery.from(book);
dslQuery.join(book.author, author);
dslQuery.where(book.title.upperIfNotBlank().like(title));
dslQuery.where(book.isbn.likeIfNotNull(isbn));
dslQuery.where(author.id.eqIfNotNull(_filter.getAuthorId()));
Run Code Online (Sandbox Code Playgroud)
如果可以打开"IfNotNull",或者甚至是默认行为
,那将会很好...... 所以最终会像这样:
dslQuery.where(book.title.upper().like(title));
dslQuery.where(book.isbn.like(isbn));
dslQuery.where(author.id.eq(_filter.getAuthorId()));
Run Code Online (Sandbox Code Playgroud) 在为实体书构建谓词时,我希望能够在类别(ManyToMany)上保持连接以在类别上添加AND谓词.如果我有JPAQuery实例,我可以简单地实现:
if (catId != null) {
jpaQuery.leftJoin(book.categories, category);
jpaQuery.where(category.id.eq(catId).or(category.parentCategory.id.eq(catId)));
}
Run Code Online (Sandbox Code Playgroud)
但是在构建Predicates时我还没有JPAQuery.所以对于Predicate本身我可以这样做:
booleanBuilder.and(category.id.eq(this.categoryId).or(category.parentCategory.id.eq(this.categoryId)));
Run Code Online (Sandbox Code Playgroud)
但是对于leftjoin如何在没有jpaQuery实例的情况下继续进行?
我一直在使用JPA和Postgres数据库运行Spring-Boot.根据我的网络环境,启动阶段阻止超过15秒:
INFO o.h.tool.hbm2ddl.SchemaValidator - HHH000229: Running schema validator
Run Code Online (Sandbox Code Playgroud)
奇怪的是我的数据库是本地的.任何的想法 ?
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
spring.jpa.hibernate.ddl-auto= validate
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/cine
Run Code Online (Sandbox Code Playgroud) 我想定义一个返回Observable的方法,但是我没有任何数据,我应该起诉什么签名?
myMethod(): Observable<null>;
myMethod(): Observable<void>;
myMethod(): Observable<{}>;
Run Code Online (Sandbox Code Playgroud)
在对方法中的返回进行编码时,我想在我的第一个订阅回调中接收下一个事件,所以我不能使用Observable.empty();
我可以使用以下内容:
myMethod(): Observable<null>; //I could use return Observable.of(null);
myMethod(): Observable<void>; //I could use return Observable.of(null);
myMethod(): Observable<{}>; //I could use return Observable.of({});
Run Code Online (Sandbox Code Playgroud)
我没有找到正式的方法,但也许有一个标准的解决方案......什么是最佳做法?
我能够调试jboss-eap 6.2,但我必须启动和停止服务器.在eclipse下使用Kepler SR2(使用JBosstools)当我在调试模式下启动时,Junit测试会冻结显示控制台:
mars 14, 2014 8:45:15 AM org.jboss.as.arquillian.container.managed.ManagedDeployableContainer startInternal
INFO: Starting container with: ["C:\Program Files\Java\jdk1.7.0_25\bin\java", -Xdebug, -agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=y, -ea, -Djboss.home.dir=C:\_server\jboss-eap-6.2, -Dorg.jboss.boot.log.file=C:\_server\jboss-eap-6.2\standalone\log\boot.log, -Dlogging.configuration=file:/C:/_server/jboss-eap-6.2/standalone/configuration/logging.properties, -Djboss.bundles.dir=C:\_server\jboss-eap-6.2\bundles, -jar, C:\_server\jboss-eap-6.2\jboss-modules.jar, -mp, C:\_server\jboss-eap-6.2\modules, -jaxpmodule, javax.xml.jaxp-provider, org.jboss.as.standalone, -server-config, standalone.xml]
Listening for transport dt_socket at address: 8787
Run Code Online (Sandbox Code Playgroud)
然后,如果我在eclispe下启动JBOss-eap,则测试在启用断点的情况下运行正常.最后服务器没有停止,我必须手动停止它
我做错了什么?
这是我的Aquillian conf(在windows7上工作):
<container qualifier="jboss" default="true">
<configuration>
<property name="jbossHome">C:\_server\jboss-eap-6.2</property>
<property name="javaVmArguments">-Xdebug -agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=y</property>
<property name="javaHome">C:\Program Files\Java\jdk1.7.0_25</property>
</configuration>
</container>
Run Code Online (Sandbox Code Playgroud)
这是pom.xml和paretn pom之后
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>ee6-parent-root</artifactId>
<groupId>sopra.academy.jee6</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>ee6-parent-ejb-junit</artifactId>
<packaging>pom</packaging>
<repositories>
<repository>
<id>thirdparty-releases</id>
<name>JBoss Thirdparty Releases</name>
<url>https://repository.jboss.org/nexus/content/repositories/thirdparty-releases</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId> …Run Code Online (Sandbox Code Playgroud) 尝试访问 this () 上下文上的别名值,我按照https://docs.cypress.io/api/commands/as#Fixture中的文档进行操作
在 .then 回调中,dataExample 参数已填充正常,但在 this.example 上它是未定义的。
describe('cy.as and this', function () {
it('Testing cy.as and this', function () {
cy.fixture('example.json').as('example')
.then(function (dataExample) {
cy.log('ACCESSING this, dataExample', this, dataExample);
});
cy.log(`ACCESSING this.example : ${JSON.stringify(this['example'])}`, this);
});
});
Run Code Online (Sandbox Code Playgroud)
第一个日志输出以下内容: dataExample 已正确填充,但 contex.example 未定义

.then 之外的第二个日志, this.example 也未定义

如果我将 cy.fixture 行移到 beforeEach() 中,它就会起作用。冷有人解释一下这种行为吗?
describe('alias', () => {
beforeEach(() => {
cy.fixture('example.json').as('example');
});
it('can access all aliases as properties', function () {
expect(this['example']).not.to.eq(undefined); // true
cy.log('THIS', this); // curious …Run Code Online (Sandbox Code Playgroud) spring-boot ×3
java ×2
querydsl ×2
cypress ×1
hibernate ×1
observable ×1
rxjs ×1
spring ×1
spring-aop ×1
spring-rest ×1
typescript ×1