当前位置: 首页 > 知识库问答 >
问题:

必须从Java代理开始才能使用InstrumentationLoadTimeWeaver。参见Spring文档

郤立果
2023-03-14
Jun 01, 2017 5:53:26 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Jun 01, 2017 5:53:26 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/remember-friends] startup failed due to previous errors
Jun 01, 2017 5:53:26 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
Jun 01, 2017 5:53:26 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/remember-friends] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak.
Jun 01, 2017 5:53:26 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-9090"]

    @Bean
        public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws IOException {
            EclipseLinkJpaVendorAdapter vendorAdapter = new EclipseLinkJpaVendorAdapter();
            vendorAdapter.setShowSql(true);
            LocalContainerEntityManagerFactoryBean entityManagerFacotryBean= new LocalContainerEntityManagerFactoryBean();
            entityManagerFacotryBean.setJpaVendorAdapter(vendorAdapter);
            entityManagerFacotryBean.setDataSource(getDataSource());
            entityManagerFacotryBean.setPackagesToScan("com.navin.friends.domain.entity");
            entityManagerFacotryBean.setJpaProperties(getJPAProperties());
            entityManagerFacotryBean.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
            entityManagerFacotryBean.setPersistenceUnitName("friends");
            entityManagerFacotryBean.setJpaDialect(new EclipseLinkJpaDialect());
            return entityManagerFacotryBean;

        }

共有1个答案

颜楚青
2023-03-14

您需要包括spring-instrument.jar代理:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.4</version>
    <configuration>
            <forkMode>once</forkMode>
            <argLine>
                 -javaagent:"${settings.localRepository}/org/springframework/spring-instrument/${spring.framework.version}/spring-instrument-${spring.framework.version}.jar"
        </argLine>
            <useSystemClassloader>true</useSystemClassloader>
    </configuration>
</plugin>

(用您的值替换${spring.framework.version}和${settings.local仓库})

当然还有一个AspecJ Maven插件:

<plugin>
     <groupId>org.codehaus.mojo</groupId>
     <artifactId>aspectj-maven-plugin</artifactId>
     <version>1.3</version>
     <executions>
         <execution>
             <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>                     
             <goals>
                 <goal>compile</goal>       <!-- use this goal to weave all your main classes -->
                 <goal>test-compile</goal>  <!-- use this goal to weave all your test classes -->
             </goals>
         </execution>
    </executions>
</plugin>

要使AspectJ正常工作,还需要添加aspectjrt依赖项:

<dependency>
  <groupId>org.aspectj</groupId>
  <artifactId>aspectjrt</artifactId>
  <version>${aspectjrt.version}</version>
</dependency>
 类似资料: