在遵循各种示例并阅读 spring 引导文档后,我仍然无法启用休眠统计。我正在 application.properties 文件中设置属性。通过集成测试运行 spring boot 应用程序或不Application.java产生任何统计信息。
我的application.properties档案。
spring.datasource.jdbcUrl=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username = postgres
spring.datasource.password = password
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.platform=postgres
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.generate_statistics=true
logging.level.org.hibernate.SQL=TRACE
logging.level.org.hibernate.stat=TRACE
logging.file=transaction-app.log
Run Code Online (Sandbox Code Playgroud)
logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
<root level="INFO">
<appender-ref ref="FILE" />
</root>
</configuration>
Run Code Online (Sandbox Code Playgroud)
还有我的集成测试
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class SqlMappingTest {
@Autowired
PlanService planService;
@org.junit.Test
public void findAll() {
List<Plan> plans = planService.findAll();
Assert.assertEquals(1, plans.size());
} …Run Code Online (Sandbox Code Playgroud) 我正在使用Shiro作为安全框架创建一个App.该应用程序有两个部分; 网络和休息.
网络正在使用Shiro的默认设置FormAuthenticationFilter.我对基于会话的方法感到满意.
使用Rest的独立应用程序,我想限制使用FormAuthenticationFilter和创建会话,我可以通过shiro.ini文件来完成
我需要在其余服务上实现基于凭据的安全性.
在网上浏览我看到一些博客建议你创建自己的Realm和过滤器来处理这种情况.但没有关于如何做到这一点的细节.
是否可以在Apache Shiro上实现基于凭据的安全性?如果有,是否有博客或教程向您展示如何实现这一目标?
问候
我有一个多次调用的角度服务功能.在index.html页面中我有以下行:
<li><i class="pull-right"></i><br/>{{appCtrl.service.getCurrentUser()}} </li>
Run Code Online (Sandbox Code Playgroud)
在应用程序控制器中,我设置了变量
appCtrl.controller('AppController', function ($state, securityService, $log) {
$log.info('App controller');
var appCtrl = this;
appCtrl.service = securityService;
});
Run Code Online (Sandbox Code Playgroud)
在我的服务中,我公开了这个功能
login.factory('securityService', function ($window, $log) {
var currentUser;
return {
setCurrentUser: function (user) {
currentUser = user;
$window.sessionStorage.setItem('User', JSON.stringify(currentUser));
},
getCurrentUser: function () {
$log.info('Calling current user');
if (!currentUser) {
var storedObject = $window.sessionStorage.getItem('User');
currentUser = JSON.parse(storedObject);
}
return currentUser;
}
}
});
Run Code Online (Sandbox Code Playgroud)
getCurrentUser当应用程序启动或页面刷新完成时,函数中的以下行会被多次调用.
$log.info('Calling current user');
Run Code Online (Sandbox Code Playgroud)
控制器只被调用一次,我通过查看来监控它 $log.info('App controller');
是作为脏检查过程的一部分被调用还是我做错了什么?
我试图通过save在事务中运行多个方法来原子地保存许多实体,因此如果其中任何一个失败,所有这些都将被丢弃(回滚)。我尝试了很多东西,但似乎没有任何效果:
预订资源.java:
@RestController
public class BookingResource {
@Autowired
private ReservationRepository reservationRepository;
@PostMapping("/booking")
@Transactional(noRollbackFor=RuntimeException.class)
public ResponseEntity<BookingResourceResponse> createReservtion(@RequestBody Reservation body) {
//code...
try {
int day = 0;
do {
reservationRepository.save(new Reservation(..., day));
}
while(day <= LIMIT_VALUE);
return buildResponse(HttpStatus.CREATED, new BookingResourceResponse(body));
}
catch(Exception e) {
return buildResponse(HttpStatus.CONFLICT, new BookingResourceResponse("Some error here"));
}
}
}
Run Code Online (Sandbox Code Playgroud)
ReservationRepository.java :
public interface ReservationRepository extends JpaRepository<Reservation, Long> {
}
Run Code Online (Sandbox Code Playgroud)
预订.java :
@Entity
public class Reservation {
@Id
@Column(name="reservation_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private …Run Code Online (Sandbox Code Playgroud)