我正在尝试将我的项目转换为Spring Boot项目(嵌入Jetty的可执行jar文件).所有工作都使用标准示例,但我希望将旧的web.xml迁移到Spring Boot.
我迁移了Servlet和过滤器,但我不明白如何迁移过滤器:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<listener>
<listener-class>org.granite.config.GraniteConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.granite.gravity.websocket.GravityWebSocketDeployer</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)
我创建了@SpringBootApplication类,并在所有配置中编写:
@Bean
@Order(1)
public FilterRegistrationBean springSecurityFilterChain() {
FilterRegistrationBean filterRegBean = new FilterRegistrationBean();
DelegatingFilterProxy delegatingFilterProxy = new DelegatingFilterProxy();
filterRegBean.setFilter(delegatingFilterProxy);
List<String> urlPatterns = new ArrayList<String>();
urlPatterns.add("/*");
filterRegBean.setUrlPatterns(urlPatterns);
return filterRegBean;
}
Run Code Online (Sandbox Code Playgroud)
有人可以解释我应该如何转换听众?
是否可以从客户端向所有传出的cxf连接添加标头.
使用Spring 3.0和CXF 2.6.0
我有一个大文件,我正在打开一个FileInputStream.此文件包含一些文件,每个文件都有一个从开头和大小的偏移量.此外,我有一个解析器,应该评估这样一个包含的文件.
File file = ...; // the big file
long offset = 1734; // a contained file's offset
long size = 256; // a contained file's size
FileInputStream fis = new FileInputStream(file );
fis.skip(offset);
parse(fis, size);
public void parse(InputStream is, long size) {
// parse stream data and insure we don't read more than size bytes
is.close();
}
Run Code Online (Sandbox Code Playgroud)
我觉得这不是好习惯.有没有更好的方法来做到这一点,也许使用缓冲?
此外,我觉得skip()方法会大大减慢阅读过程.
我想将 Socat 用于我的 android 应用程序。有人在 Android 下移植 Socat 吗?找不到任何有用的链接。任何帮助都会很棒。
使用Hibernate的@NaturalId查找对象有什么好处吗?
我担心Hibernate使用@NaturalId执行两个查询以获取对象这一事实.第一个查询只是为了获取id和第二个查询来加载真实对象.
我正在查看在 Java 8 中使用 Predicate 的代码。有人可以帮助我了解使用 Predicate 的最佳情况吗?什么情况下需要使用Predicate,什么情况下需要使用if条件?
我们需要跟踪数据库指标,因此我们使用 datasource-proxy 来跟踪它,以将其集成到我们创建的自定义数据源的 Spring Boot 项目中,如下所示
@Component
@Slf4j
@ConfigurationProperties(prefix = "spring.datasource")
public class DataSourceBeanConfig
{
public DataSource actualDataSource()
{
EmbeddedDatabaseBuilder databaseBuilder = new EmbeddedDatabaseBuilder();
return databaseBuilder.setType(EmbeddedDatabaseType.H2).build();
}
@Bean
@Primary
public DataSource dataSource() {
// use pretty formatted query with multiline enabled
PrettyQueryEntryCreator creator = new PrettyQueryEntryCreator();
creator.setMultiline(true);
log.info("Inside Proxy Creation");
SystemOutQueryLoggingListener listener = new SystemOutQueryLoggingListener();
listener.setQueryLogEntryCreator(creator);
return ProxyDataSourceBuilder
.create(actualDataSource())
.countQuery()
.name("MyDS")
.listener(listener)
.build();
}
}
Run Code Online (Sandbox Code Playgroud)
当我们运行主应用程序时,数据源代理被拾取,但是当我们使用@DataJpaTest时,它没有被拾取。如何在 JUNIT 测试用例中启用数据源代理?
编辑::
使用SpringBeanPostProcessor配置Proxy DataSource
@Slf4j
@Configuration
public class DataSourceBeanConfig implements BeanPostProcessor …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中面临一个奇怪的问题,它运行在Spring Boot 1.4.0M3上,它使用Spring缓存实现,其中provider是Redis,我收到classCastException,相同的对象无法生成
我使用Mongodb作为数据库,我有User Object,其中包含懒惰加载的Roles对象列表,Roles内部包含权限对象,如下所示
@Document
@Data
public class User implements Serializable{
private String passwordResetToken;
private boolean enabled = false;
@DBRef(lazy= true)
private List<Role> roleList;
}
Run Code Online (Sandbox Code Playgroud)
我的角色DTO如下
@Data
@Document
public class Role implements Serializable{
private String roleName;
private String description;
@DBRef(lazy= true)
private List<Permission> permissions;
}
Run Code Online (Sandbox Code Playgroud)
现在在我的Spring MVC加载所有角色时我调用所有权限,因为这是重复操作,我想到缓存结果并使用redis,同时加载我在异常下面收到的角色值.
raised java.lang.ClassCastException: com.learning.securedapp.domain.Permission cannot be cast to com.learning.securedapp.domain.Permission
Run Code Online (Sandbox Code Playgroud)
帮助我克服这个错误.
我将源代码附加到我的项目,并在RoleController.java的第91行收到错误
要在本地环境中复制,请登录到应用程序,然后单击权限菜单,然后单击角色菜单,在角色菜单中,现在单击任何编辑图标.您将收到以上错误.
我正在使用spring boot 1.3.6并且我的JUNIT测试用例运行正常,升级到spring boot 1.4.0并尝试删除已弃用的类会让我错误
我的JUNITCLASS 1.3.x
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
@IntegrationTest({"server.port=0"})
public class CustomerControllerIT {
@Value("${local.server.port}")
private int port;
private URL base;
private RestTemplate template;
@Autowired
private DataBuilder dataBuilder;
@Autowired
private CustomerRepository customerRepository;
private static final String JSON_CONTENT_TYPE = "application/json;charset=UTF-8";
@Before
public void setUp() throws Exception {
this.base = new URL("http://localhost:" + port + "/rest/customers");
template = new TestRestTemplate();
/* remove and reload test data */
customerRepository.deleteAll();
dataBuilder.createCustomers().forEach(customer -> customerRepository.save(customer));
}
@Test
public void getAllCustomers() throws Exception { …Run Code Online (Sandbox Code Playgroud) 我已经安装了SonarQube 5.1.2和Checkstyle插件2.3。
问题:如何导入Checkstyle XML配置文件?当我尝试将预安装的FindBugs或Checkstyle规则配置导出到XML文件时,导出将起作用。然后,我尝试使用其他名称导入相同的规则,但它不起作用。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="severity" value="warning"/>
<module name="TreeWalker">
<module name="JavadocMethod">
<property name="scope" value="public"/>
<property name="suppressLoadErrors" value="true"/>
</module>
<module name="JavadocType">
<property name="scope" value="public"/>
<property name="authorFormat" value="^.../[^,]+(,\s.../[^,]+)*$"/>
</module>
<module name="JavadocVariable">
<property name="scope" value="public"/>
</module>
<module name="JavadocStyle"/>
<module name="ConstantName"/>
<module name="LocalFinalVariableName">
<property name="format" value="^[a-z_][a-zA-Z0-9]*$"/>
</module>
<module name="LocalVariableName">
<property name="format" value="^[a-z_][a-zA-Z0-9]*$"/>
</module>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>
<module name="AvoidStarImport"/>
<module name="IllegalImport"/>
<module …Run Code Online (Sandbox Code Playgroud) spring ×4
spring-boot ×4
java ×3
caching ×2
android ×1
checkstyle ×1
client ×1
cxf ×1
hibernate ×1
import ×1
inputstream ×1
java-8 ×1
junit4 ×1
listener ×1
natural-key ×1
orm ×1
redis-cache ×1
rules ×1
socat ×1
sonarqube ×1
spring-mvc ×1
spring-test ×1
web.xml ×1
xml ×1