Spring Boot 1.3.5范围会话

时间:2017-12-28 20:08:17

标签: spring-boot

我正在使用Spring Boot 1.3.5开发一个项目。 我想在我的bean中添加范围注释。 我试过@Scope(value =" session")和@SessionScoped。 但这无法解决我的问题。

Bellow,是我的文件pom.xml:



<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.5.RELEASE</version>
</parent>
  
  
  <groupId>SpringBootFirstApp</groupId>
  <artifactId>springbootfirstapp</artifactId>
 
  <version>0.0.1-SNAPSHOT</version>
 
 
  <packaging>war</packaging>
 
 

<repositories>
	<repository>
		<id>prime-repo</id>
		<name>Prime Repo</name>
		<url>http://repository.primefaces.org</url>
	</repository>
</repositories>

<properties>
        <!-- can be 8 also -->
		<java.version>7</java.version>
    
        <!-- can be 8.0.x also -->
        <tomcat.version>7.0.62</tomcat.version>
        
        <jsf-mojarra.version>2.2.11</jsf-mojarra.version>
       
	</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
  </dependency>
  
  <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
  
 
  <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>      
      
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>6.0</version>
        </dependency>

	<dependency>
		<groupId>org.primefaces.themes</groupId>
		<artifactId>glass-x</artifactId>
		<version>1.0.6</version>
	</dependency>
		
	
		<dependency>
			<groupId>org.glassfish</groupId>
			<artifactId>javax.faces</artifactId>
			<version>${jsf-mojarra.version}</version>
		</dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
  
  <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
  
</dependencies>
  <build>
     <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                    <!-- Eclipse: If Eclipse configured to refresh the workspace automatically,
                                  "mvn spring-boot:run" can fail in some rare cases.
                    -->
                    <addResources>false</addResources>
                </configuration>
        </plugin>
    </plugins>
  </build>
</project>
&#13;
&#13;
&#13;

在使用Spring Boot 1.3.5时,有没有想过如何使用会话范围注释来注释bean? 提前谢谢。

1 个答案:

答案 0 :(得分:0)

你可以尝试:

&#13;
&#13;
@Component
@Scope("session")
public class MyBean implements ApplicationContextAware, Serializable
{
  ...
}
&#13;
&#13;
&#13;

HTH