小编ygl*_*odt的帖子

Spring JavaConfig:为自定义Servlet添加映射

在基于javaconfig的Spring 4.0项目中,如何将某个URL的映射添加到除Spring DispatcherServlet之外的Servlet.

我的情况我想使用H2数据库中的h2console,这是通过servlet提供的 org.h2.server.web.WebServlet

编辑:在即将到来的Spring Boot 1.3中,可以使用配置参数启用h2console:http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-sql-h2 -安慰

启用它就像将这两行添加到您的application.properties:

spring.h2.console.enabled=true
spring.h2.console.path=/console
Run Code Online (Sandbox Code Playgroud)

java spring h2 spring-boot

7
推荐指数
1
解决办法
5176
查看次数

如何在Android中解压缩7zip存档?

我有一个7zip存档,其中包含分成不同目录的几百个文件.目标是从FTP服务器下载它,然后在手机上提取它.

我的问题是7zipSDK不包含很多.我正在寻找有关7z文件解压缩的示例,教程和片段.

(减压通过Intent只是次要选项)

java android 7zip archive

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

无法获取当前线程的事务同步会话

我使用从xml-转换为Java-Config的Spring4/Hibernate4项目获得以下异常.

org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
Run Code Online (Sandbox Code Playgroud)

该项目在Eclipse中启动属性和errorfree,但在第一个请求时出现Exception.在我ConfigRoot-class我已经@Bean配置为DataSource,SessionFactory,HibernateTransactionManager,ImprovedNamingStrategy.

我的所有@Service服务都注明了@Transactional.

知道这可能来自哪里?

编辑1

根据要求,这里是stacktrace:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
    org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:134)
    org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014)
    employees.service.PersonService.getAllInHierarchcalOrder(PersonService.java:58)
    employees.controller.PersonController.getPersons(PersonController.java:64)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:606)
    org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) …

java spring hibernate spring-java-config

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

PI4J - 无法使用路径加载 [libpi4j.so]

我在 MacOS 上使用 NetBeans 来开发使用 PI4J 的应用程序。一切看起来都不错,但我收到以下错误,指出 PI4J 无法加载。有谁知道如何解决这个问题?

abr 18, 2015 3:02:30 PM com.pi4j.util.NativeLibraryLoader load
SEVERE: Unable to load [libpi4j.so] using path: [/lib/libpi4j.so]
java.lang.UnsatisfiedLinkError: /private/var/folders/0x/6rph2scs0f544b7xwkfhzkcw0000gn/T/libpi4j3968879292977354112.so: dlopen(/private/var/folders/0x/6rph2scs0f544b7xwkfhzkcw0000gn/T/libpi4j3968879292977354112.so, 1): no suitable image found.  Did find:
    /private/var/folders/0x/6rph2scs0f544b7xwkfhzkcw0000gn/T/libpi4j3968879292977354112.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1937)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1822)
    at java.lang.Runtime.load0(Runtime.java:809)
    at java.lang.System.load(System.java:1086)
    at com.pi4j.util.NativeLibraryLoader.loadLibraryFromClasspath(NativeLibraryLoader.java:143)
    at com.pi4j.util.NativeLibraryLoader.load(NativeLibraryLoader.java:92)
    at com.pi4j.wiringpi.Gpio.<clinit>(Gpio.java:174)
    at com.pi4j.io.gpio.RaspiGpioProvider.<init>(RaspiGpioProvider.java:51)
    at com.pi4j.io.gpio.GpioFactory.getDefaultProvider(GpioFactory.java:106)
    at com.pi4j.io.gpio.impl.GpioControllerImpl.<init>(GpioControllerImpl.java:54)
    at com.pi4j.io.gpio.GpioFactory.getInstance(GpioFactory.java:89)
    at hellorasp.HelloRasp.main(HelloRasp.java:31)

Exception in thread "main" …
Run Code Online (Sandbox Code Playgroud)

java macos netbeans raspberry-pi pi4j

6
推荐指数
1
解决办法
7608
查看次数

使用zeroconf可以发现Spring Boot应用程序

如何Java构建可Spring Boot发现的Web应用程序应用程序zeroconf

我试过以下JmDNS但它似乎不起作用:

@Bean
public JmDNS jmdns() {
    try {
        JmDNS jmdns = JmDNS.create(InetAddress.getLocalHost());
        ServiceInfo serviceInfo = ServiceInfo.create("_http._tcp.local.", "appName", port, "path=index.html");
        jmdns.registerService(serviceInfo);
        return jmdns;
    } catch (final Exception e) {
        logger.error(e.getMessage());
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

在此之后,我希望能够在Windows 10网络概述中看到该服务,但它不会出现在那里.

编辑

该应用程序列在avahi浏览器中,显示它以某种方式工作.

但我的目标是让它在Windows网络服务概述中可见.

java windows zeroconf jmdns spring-boot

6
推荐指数
0
解决办法
292
查看次数

在JavaScript中使用Thymeleaf forEach循环

我正在将项目从JSP迁移到Thymeleaf.

在一些JSP中我做了像这样的花哨的东西:

<script type="text/javascript">
    //<c:forEach items="${pages}" var="page">

    ...
    var l = new google.maps.LatLng("${page.lat}", "${page.long}");
    ...

    //</c:forEach>
</script>
Run Code Online (Sandbox Code Playgroud)

我怎么能和Thymeleaf一样呢?

jsp jstl thymeleaf

6
推荐指数
1
解决办法
5156
查看次数

Thymeleaf 3.0 Spring Boot +安全集成不起作用

我很难让Thymeleaf在我的基于Spring Boot 1.4.3的项目中使用Spring Security.

标签如,例如

<div sec:authorize="hasAuthority('ADMIN')">
Run Code Online (Sandbox Code Playgroud)

根本就没有解析.

如果我尝试SpringSecurityDialect像这样手动添加:

@Bean
public SpringSecurityDialect securityDialect() {
    return new SpringSecurityDialect();
}
Run Code Online (Sandbox Code Playgroud)

我正进入(状态:

Exception in thread "main" java.lang.NoClassDefFoundError: org/thymeleaf/dialect/IExpressionEnhancingDialect
Run Code Online (Sandbox Code Playgroud)

我在我的依赖项中包含以下内容:

<dependency>
    <groupId>org.thymeleaf.extras</groupId>
    <artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

SpringSecurityDialect似乎并没有被自动配置添加.

在我手动添加Bean之后,我得到了提到的异常.

这是一个错误还是我错过了什么?

我的Thymeleaf版本是:

<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-extras-java8time.version>3.0.0.RELEASE</thymeleaf-extras-java8time.version>
<thymeleaf-layout-dialect.version>2.1.2</thymeleaf-layout-dialect.version>
Run Code Online (Sandbox Code Playgroud)

java spring-security thymeleaf spring-boot

6
推荐指数
1
解决办法
5717
查看次数

根据用户名和远程IP地址使用不同的AuthenticationProvider

在基于 Spring Security 3.2 的应用程序中,我需要根据用户名和远程 IP 地址中的特定模式,针对两个不同的提供者对用户进行身份验证。

如果它们符合某些规则,则应根据 进行身份验证,否则应使用使用现有自定义实现的ActiveDirectoryLdapAuthenticationProvider标准进行身份验证。AuthenticationProviderUserDetailsService

我需要延长什么?AuthenticationManager或者AuthenticationProvider?任何示例代码将不胜感激:-)

注意:我已经成功尝试<authentication-provider />在 中添加两个节点<authentication-manager />,并且效果很好。但令我困扰的是,我的 Ldap 服务器每次身份验证尝试都会受到攻击(即使是那些不适合它的尝试)

spring spring-security spring-ldap

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

如何在表单提交中包含Polymer paper-dropdown-menu

当我提交这个带有document.getElementById("form").submit();firstName的last 表单时,lastName包含在POST数据中,但是paper-dropdown-menu中的title-value没有.缺什么 ?

<form is="iron-form" id="form" method="post" action="/edit">
    <paper-dropdown-menu name="title" label="Title">
        <paper-menu class="dropdown-content">
            <template is="dom-repeat" items="{{titles}}" as="title">
                <paper-item value="{{item.id}}">{{title.name}}</paper-item>
            </template>
        </paper-menu>
    </paper-dropdown-menu>
    <paper-input name="firstName" label="First name"></paper-input>
    <paper-input name="lastName" label="Last name"></paper-input>
    <paper-button raised onclick="submitForm()">Save</paper-button>
</form>
Run Code Online (Sandbox Code Playgroud)

编辑:

在这里,我完整的工作实例,非常感谢@Brandon的回答:

<form is="iron-form" id="form" method="post" action="/api/edit">
    <paper-dropdown-menu label="Title" selected-item="{{selectedItem}}" selected-item-label="{{selected}}">
        <paper-menu class="dropdown-content">
            <template is="dom-repeat" items="{{titles}}" as="title">
                <paper-item value="[[title.id]]">[[title.name]]</paper-item>
            </template>
        </paper-menu>
    </paper-dropdown-menu>
    <input is="iron-input" name="title" type="hidden" value$="[[selectedItem.value]]">
    <paper-input name="firstName" label="First name"></paper-input>
    <paper-input name="lastName" label="Last name"></paper-input>
    <paper-button raised onclick="document.getElementById('form').submit()">Save</paper-button>
</form>
Run Code Online (Sandbox Code Playgroud)

html5 polymer

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

如何从模型数据中预先选择纸张下拉菜单中的纸张项目?

我的项目中有一iron-form件事要做CRUD.除了一个问题之外,这很有效.

如何paper-dropdown-menu从模型数据中显示值?(即:paper-item从我的模型数据中预选对应于[[o.id]]值)

selected属性paper-menu并没有帮助,因为基于的价值它的指数为基础的,而不是paper-item.

这是表单的代码:

<form is="iron-form" id="itemForm" method="post" action="/api/item/edit">

    <input is="iron-input" name="id" type="hidden" value="{{item.id}}">

    <paper-dropdown-menu label="Title" selected-item="{{selectedTitle}}">
        <paper-menu class="dropdown-content">
            <template is="dom-repeat" items="{{titles}}" as="o">
                <paper-item value="[[o.id]]">[[o.name]]</paper-item>
            </template>
        </paper-menu>
    </paper-dropdown-menu>
    <input is="iron-input" name="title" type="hidden" value$="[[selectedTitle.value]]">

    <paper-input name="firstName" label="First name" value="{{item.firstName}}"></paper-input>

    <paper-button raised onclick="document.getElementById('itemForm').submit()">Save</paper-button>
</form>
Run Code Online (Sandbox Code Playgroud)

javascript html5 web-component polymer

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