小编use*_*051的帖子

nginx使用Tomcat 7管理SSL

在server.xml中使用nginx管理SSL的正确配置是什么?我的当前配置导致"重定向循环",除非我将tomcat标准连接标记为"安全",这不是我想要的.我的应用程序需要所有请求的https,如果使用http,则重定向到https.如果我设置secure ="true",它不再重定向,但"重定向循环"消失了.我究竟做错了什么?

我当前的tomcat server.xml:

 <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               URIEncoding="UTF-8"
               redirectPort="8443" proxyPort="443"/>
Run Code Online (Sandbox Code Playgroud)

Nginx conf:

  server {
        listen 80 default_server;
        server_name localhost, mydomain.com;

         location / {

        add_header 'Access-Control-Allow-Origin' '*';
         proxy_pass        http://localhost:8080/;
        proxy_redirect    off;
        proxy_set_header  Host               $host;
        proxy_set_header  X-Real-IP          $remote_addr;
        proxy_set_header  X-Forwarded-For    $proxy_add_x_forwarded_for;
        proxy_set_header  X-Forwarded-Proto  http;
        proxy_send_timeout 6000;
         }
        }
 server {
                 server_name localhost, mydomain.com;
                listen 443;

        ssl on;
        ssl_session_timeout 5m;
        ssl_protocols SSLv2 SSLv3 TLSv1;
        #make sure you already have this certificate pair!
        ssl_certificate /etc/nginx/cert/server.crt;
        ssl_certificate_key /etc/nginx/cert/server.key;
        ssl_session_cache shared:SSL:10m;
        error_page 497 https://$host:$server_port$request_uri;

        # …
Run Code Online (Sandbox Code Playgroud)

ssl tomcat nginx tomcat7

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

Spring 3.2 + Hibernate 4 OpenSessionInViewFilter

我是一个春天新手尝试我的第一个应用程序.我的hibernate在呈现视图之前关闭,并且在延迟加载属性(预期行为)方面存在问题.我已将OpenSessionInViewFilter添加到我的web.xml并导致以下内容:

java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
Run Code Online (Sandbox Code Playgroud)

事先用我所拥有的默认servlet上下文配置工作正常(有人可以告诉我为什么吗?).所以我添加了以下内容:

 <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/springapp-servlet.xml
    </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
Run Code Online (Sandbox Code Playgroud)

新的错误消失了..但仍然从hibernate获得no会话异常

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.test.model.Store.categories, could not initialize proxy - no Session
Run Code Online (Sandbox Code Playgroud)

我在我的一个控制器中放了一个调试消息,似乎它被初始化了3次.也许我有多个hibernate会话工厂bean的实例?我的控制器方法标记为@Transactional,一切正常,直到我试图打开会话以使视图可用的惰性字段.

我的完整web.xml(添加了新的上下文,在我添加了hibernate过滤器之前没有它工作正常):

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app version="2.4"
         xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" > 
    <display-name>
      Spring
    </display-name>
    <description>
     Spring Test
    </description>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/springapp-servlet.xml
    </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

   <filter>
      <filter-name>hibernateFilter</filter-name>
      <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
      <init-param>
         <param-name>sessionFactoryBeanName</param-name>
         <param-value>sessionFactory</param-value>         
      </init-param>      
   </filter>

   <filter-mapping>
     <filter-name>hibernateFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
   </filter-mapping> 

  <servlet>
    <servlet-name>springapp</servlet-name> …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate

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

Java JSON 对象扁平化

我正在寻找一个 Java 库来将我的域对象转换为扁平化的 JSON

例如。

public class Person {
   String name
   Address homeAddress
}

public class Address {
  String street
  String zip
}

JSON: {name:'John', homeAddress_street: '123 Street', homeAddress_zip: 'xxxxx'}
Run Code Online (Sandbox Code Playgroud)

我研究过 XStream、Eclipse MOXy、FlexJSON、JSON-lib 和 gson

我的目标是摆脱 json 包装类并最小化代码。我想要一个通用服务,它可以接受我拥有的任何域模型类并获得 json 表示,而无需为每种类型的模型编写 xml 描述符或任何自定义转换器。对于我的模型来说,1 级深度就足够了。我还没有找到使用注释或上述库中内置功能的简单通用解决方案,但我可能忽略了它们。有没有一个非侵入式的库可以做到这一点?或者也许是我列出的一个?我正在使用 Hibernate,因此库必须能够处理 CGLib 代理

java json

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

Spring Hello World Web App

我正在试用一个Web应用程序的Spring Framework,似乎无法使用简单的hello world MVC Web应用程序.使用Spring 3.2,Tomcat 6(上下文设置为"/ spring").也许没有找到带注释的Controller类?

我打 http://localhost:8080/spring/hello

web.xml中

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app version="2.4"
         xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" > 
    <display-name>
      Spring
    </display-name>
    <description>
     Spring Test
    </description>

     <servlet>
    <servlet-name>springapp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>springapp</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>



</web-app>
Run Code Online (Sandbox Code Playgroud)

springapp-servlet.xml中

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <context:component-scan base-package="com.test.web" />
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>
Run Code Online (Sandbox Code Playgroud)

我的控制器

package com.test.web;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


@Controller
@RequestMapping("/hello")
public …
Run Code Online (Sandbox Code Playgroud)

java spring tomcat spring-mvc

4
推荐指数
1
解决办法
817
查看次数

标签 统计

java ×3

spring ×2

tomcat ×2

hibernate ×1

json ×1

nginx ×1

spring-mvc ×1

ssl ×1

tomcat7 ×1